@synnaxlabs/pluto 0.44.0 → 0.44.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.
Files changed (90) hide show
  1. package/dist/{Animated-CCN9ByY6.cjs → Animated-3QNTHym1.cjs} +1 -1
  2. package/dist/{Animated-Owbkpo6B.js → Animated-KCUNFDvN.js} +2 -2
  3. package/dist/{Menu-DZ-gh1ky.js → Menu-BFD8DPDp.js} +3 -3
  4. package/dist/{Menu-BSLsdSQe.cjs → Menu-BPH8apK8.cjs} +1 -1
  5. package/dist/{Toggle-BUJcWkDS.js → Toggle-1E6vrl6G.js} +1 -1
  6. package/dist/{Toggle-BWcSF1BX.cjs → Toggle-BHiPL61M.cjs} +1 -1
  7. package/dist/{Video-BcSAFYkH.cjs → Video-BidrtYj_.cjs} +1 -1
  8. package/dist/{Video-DqCXiObt.js → Video-Cm8ZBqid.js} +1 -1
  9. package/dist/button.cjs +1 -1
  10. package/dist/button.js +1 -1
  11. package/dist/color.cjs +1 -1
  12. package/dist/color.js +1 -1
  13. package/dist/css-9yccD6t_.cjs +8 -0
  14. package/dist/{css-Cg4qHNg7.js → css-Dl9aM7Jz.js} +694 -686
  15. package/dist/css.cjs +1 -1
  16. package/dist/css.js +2 -2
  17. package/dist/dialog.cjs +1 -1
  18. package/dist/dialog.js +1 -1
  19. package/dist/{eraser-DeKDbhe4.cjs → eraser-CLWNvWDn.cjs} +20 -20
  20. package/dist/{eraser-BPrMJQSi.js → eraser-CZknVTjw.js} +11 -11
  21. package/dist/ether.cjs +1 -1
  22. package/dist/ether.js +6 -6
  23. package/dist/{external-Dr1KTRgM.js → external-5PfK-PF3.js} +27 -27
  24. package/dist/{external-CO49SSMt.js → external-B16icDUE.js} +3 -3
  25. package/dist/{external-BZs08bQT.js → external-B1mnn7_J.js} +3 -3
  26. package/dist/{external-CmXsU6yu.cjs → external-BDFD5v83.cjs} +1 -1
  27. package/dist/{external-CwWs_qf4.js → external-BgZRkFq4.js} +2 -2
  28. package/dist/{external-ZbSTG-v-.js → external-BmaCxlPM.js} +3 -3
  29. package/dist/{external-CcIlyM7a.cjs → external-Bmv3JTk3.cjs} +1 -1
  30. package/dist/{external-BXXtl81l.js → external-Bx2Al5fy.js} +3 -3
  31. package/dist/{external-Be6wSMuJ.cjs → external-Bx2weRCW.cjs} +1 -1
  32. package/dist/{external-DCftrpz2.js → external-BzGhOwHW.js} +4 -4
  33. package/dist/{external-D9Mbu0wy.cjs → external-CKvxjJs5.cjs} +1 -1
  34. package/dist/{external-DVV0t11f.cjs → external-CtwEvFYE.cjs} +1 -1
  35. package/dist/{external-E3bYM0JI.cjs → external-DF7sP0pe.cjs} +1 -1
  36. package/dist/{external-fKroctog.js → external-DIE22vag.js} +15 -15
  37. package/dist/{external-C4JmDQou.cjs → external-DIRuVzOZ.cjs} +1 -1
  38. package/dist/{external-O7GBl914.cjs → external-DJ4pzZBh.cjs} +1 -1
  39. package/dist/external-DMB49R_H.cjs +1 -0
  40. package/dist/{external-BhHJuw2t.js → external-DPN-ziJs.js} +2 -2
  41. package/dist/{external-D2eCxMkQ.cjs → external-DRcsXa_0.cjs} +6 -6
  42. package/dist/{external-JZqEUnPB.js → external-DTzGaj9d.js} +4 -4
  43. package/dist/{external-SZ8meWoz.js → external-DWSWz3Rk.js} +3 -3
  44. package/dist/{external-D7fvHJwL.cjs → external-Dr5azzr8.cjs} +1 -1
  45. package/dist/{external-Dd9YnYGw.js → external-R1cRWCTB.js} +3 -3
  46. package/dist/{external-BHiMn0_8.cjs → external-T7fQRFNS.cjs} +1 -1
  47. package/dist/{external-bO6dVXFd.js → external-k23HUvy8.js} +12 -4
  48. package/dist/{external-Cdszmp1I.cjs → external-lMAel8Te.cjs} +1 -1
  49. package/dist/flex.cjs +1 -1
  50. package/dist/flex.js +1 -1
  51. package/dist/{fontString-BCV37JOn.js → fontString-Bm52S4Lo.js} +2 -2
  52. package/dist/{fontString-DUff-KJe.cjs → fontString-BptzSQcY.cjs} +1 -1
  53. package/dist/header.cjs +1 -1
  54. package/dist/header.js +1 -1
  55. package/dist/index.cjs +7 -7
  56. package/dist/index.js +153 -153
  57. package/dist/input.cjs +1 -1
  58. package/dist/input.js +1 -1
  59. package/dist/list.cjs +1 -1
  60. package/dist/list.js +1 -1
  61. package/dist/menu.cjs +1 -1
  62. package/dist/menu.js +1 -1
  63. package/dist/{provider-Y8rmJd2z.js → provider-BhLG7kqF.js} +3 -3
  64. package/dist/provider-DVZt686Q.cjs +53 -0
  65. package/dist/src/dialog/Dialog.d.ts.map +1 -1
  66. package/dist/src/dialog/Frame.d.ts.map +1 -1
  67. package/dist/src/list/useStaticData.d.ts.map +1 -1
  68. package/dist/src/select/MultipleTrigger.d.ts.map +1 -1
  69. package/dist/src/select/Static.d.ts +1 -1
  70. package/dist/src/select/Static.d.ts.map +1 -1
  71. package/dist/{symbols-DT8-7-NW.js → symbols-5jPiWw_d.js} +5249 -5247
  72. package/dist/{symbols-BtW1eE35.cjs → symbols-DzAWrATO.cjs} +40 -40
  73. package/dist/tabs.cjs +1 -1
  74. package/dist/tabs.js +1 -1
  75. package/dist/text.cjs +1 -1
  76. package/dist/text.js +2 -2
  77. package/dist/theming.cjs +1 -1
  78. package/dist/theming.js +2 -2
  79. package/dist/tree.cjs +1 -1
  80. package/dist/tree.js +1 -1
  81. package/dist/triggers.cjs +1 -1
  82. package/dist/triggers.js +1 -1
  83. package/dist/{units-DR4EJndw.cjs → units-BGkvnLO-.cjs} +1 -1
  84. package/dist/{units-ts2tUMPH.js → units-HcS_zslH.js} +1 -1
  85. package/dist/video.cjs +1 -1
  86. package/dist/video.js +1 -1
  87. package/package.json +5 -5
  88. package/dist/css-BR-Ih764.cjs +0 -8
  89. package/dist/external-BKWucUPD.cjs +0 -1
  90. package/dist/provider-Dx_qX7Wi.cjs +0 -53
@@ -1,53 +0,0 @@
1
- "use strict";const s=require("./css-BR-Ih764.cjs"),d=require("zod"),p=require("./eraser-DeKDbhe4.cjs"),Fe=require("./fontString-DUff-KJe.cjs");class ma{handlers;transform;closer;constructor(e,n){this.transform=e,this.handlers=n??new Map}onChange(e){return this.handlers.set(e,null),()=>this.handlers.delete(e)}notify(e){let n=e;if(this.transform!=null){const[r,i]=this.transform(e);if(!i)return;n=r}this.handlers.forEach((r,i)=>i(n))}setCloser(e){this.closer=e}async close(){return await this.closer?.()}}class ya{handlers;constructor(e){this.handlers=e??new Map}onChange(e){return this.handlers.set(e,null),()=>this.handlers.delete(e)}notify(e){this.handlers.forEach((n,r)=>r(e))}}const Ft=Object.freeze(Object.defineProperty({__proto__:null,BaseObserver:ya,Observer:ma},Symbol.toStringTag,{value:"Module"})),Nn="pluto-vis-renderer",Wt=(t,e)=>{t.set(Nn,e,!1)},Ht=t=>t.get(Nn),ss=t=>t.getOptional(Nn),X=(t,e)=>Ht(t)(e),dn=(t,e)=>async n=>{let r;n.changed.dataType.equals(s.r.JSON)?r=n.changed.parseJSON(t):r=Array.from(n.changed).map(i=>t.parse(i));for(const i of r)await e({...n,changed:i})},va=t=>async e=>{for(const n of e.changed.toStrings())await t({...e,changed:n})},ba=new Error("request for lock canceled");var Sa=function(t,e,n,r){function i(a){return a instanceof n?a:new n(function(o){o(a)})}return new(n||(n=Promise))(function(a,o){function l(h){try{c(r.next(h))}catch(f){o(f)}}function u(h){try{c(r.throw(h))}catch(f){o(f)}}function c(h){h.done?a(h.value):i(h.value).then(l,u)}c((r=r.apply(t,e||[])).next())})};class xa{constructor(e,n=ba){this._value=e,this._cancelError=n,this._queue=[],this._weightedWaiters=[]}acquire(e=1,n=0){if(e<=0)throw new Error(`invalid weight ${e}: must be positive`);return new Promise((r,i)=>{const a={resolve:r,reject:i,weight:e,priority:n},o=is(this._queue,l=>n<=l.priority);o===-1&&e<=this._value?this._dispatchItem(a):this._queue.splice(o+1,0,a)})}runExclusive(e){return Sa(this,arguments,void 0,function*(n,r=1,i=0){const[a,o]=yield this.acquire(r,i);try{return yield n(a)}finally{o()}})}waitForUnlock(e=1,n=0){if(e<=0)throw new Error(`invalid weight ${e}: must be positive`);return this._couldLockImmediately(e,n)?Promise.resolve():new Promise(r=>{this._weightedWaiters[e-1]||(this._weightedWaiters[e-1]=[]),wa(this._weightedWaiters[e-1],{resolve:r,priority:n})})}isLocked(){return this._value<=0}getValue(){return this._value}setValue(e){this._value=e,this._dispatchQueue()}release(e=1){if(e<=0)throw new Error(`invalid weight ${e}: must be positive`);this._value+=e,this._dispatchQueue()}cancel(){this._queue.forEach(e=>e.reject(this._cancelError)),this._queue=[]}_dispatchQueue(){for(this._drainUnlockWaiters();this._queue.length>0&&this._queue[0].weight<=this._value;)this._dispatchItem(this._queue.shift()),this._drainUnlockWaiters()}_dispatchItem(e){const n=this._value;this._value-=e.weight,e.resolve([n,this._newReleaser(e.weight)])}_newReleaser(e){let n=!1;return()=>{n||(n=!0,this.release(e))}}_drainUnlockWaiters(){if(this._queue.length===0)for(let e=this._value;e>0;e--){const n=this._weightedWaiters[e-1];n&&(n.forEach(r=>r.resolve()),this._weightedWaiters[e-1]=[])}else{const e=this._queue[0].priority;for(let n=this._value;n>0;n--){const r=this._weightedWaiters[n-1];if(!r)continue;const i=r.findIndex(a=>a.priority<=e);(i===-1?r:r.splice(0,i)).forEach(a=>a.resolve())}}}_couldLockImmediately(e,n){return(this._queue.length===0||this._queue[0].priority<n)&&e<=this._value}}function wa(t,e){const n=is(t,r=>e.priority<=r.priority);t.splice(n+1,0,e)}function is(t,e){for(let n=t.length-1;n>=0;n--)if(e(t[n]))return n;return-1}var Ta=function(t,e,n,r){function i(a){return a instanceof n?a:new n(function(o){o(a)})}return new(n||(n=Promise))(function(a,o){function l(h){try{c(r.next(h))}catch(f){o(f)}}function u(h){try{c(r.throw(h))}catch(f){o(f)}}function c(h){h.done?a(h.value):i(h.value).then(l,u)}c((r=r.apply(t,e||[])).next())})};class as{constructor(e){this._semaphore=new xa(1,e)}acquire(){return Ta(this,arguments,void 0,function*(e=0){const[,n]=yield this._semaphore.acquire(1,e);return n})}runExclusive(e,n=0){return this._semaphore.runExclusive(()=>e(),1,n)}isLocked(){return this._semaphore.isLocked()}waitForUnlock(e=0){return this._semaphore.waitForUnlock(1,e)}release(){this._semaphore.isLocked()&&this._semaphore.release()}cancel(){return this._semaphore.cancel()}}const Ea=d.z.object({props:p.Xp.nullable(),state:p.Qp.connectivity.connectionStateZ.nullable()}),Bn={client:null};let pt=class os extends p.Composite{static TYPE="synnax.Provider";static stateZ=Ea;schema=os.stateZ;afterUpdate(e){if(e.wasSetPreviously(Un)||nn(e,Bn),this.state.props==null){this.internal.client!=null&&(this.internal.client?.close(),this.internal.client=null),nn(e,this.internal);return}this.prevState.props!=null&&p.m.equal(this.state.props,this.prevState.props)&&this.internal.client!=null||(this.internal.client=new p.Qp(this.state.props),nn(e,this.internal))}};const Un="pluto-client-context",nn=(t,e)=>t.set(Un,e),Ae=t=>t.get(Un)?.client??null,ls={[pt.TYPE]:pt},Ca=Object.freeze(Object.defineProperty({__proto__:null,Provider:pt,REGISTRY:ls,ZERO_CONTEXT_VALUE:Bn,use:Ae},Symbol.toStringTag,{value:"Module"})),Pa=d.z.object({region:s.$t.box,clearOverScan:s.J.crudeZ.optional().default(0),visible:d.z.boolean().optional().default(!0)}),Er=["upper2d","lower2d"];class Te extends p.Composite{static TYPE="Table";static stateZ=Pa;schema=Te.stateZ;afterUpdate(e){const{internal:n}=this;n.renderCtx=p.Context.use(e),n.handleError=p.useErrorHandler(e),Wt(e,()=>{this.state.visible&&this.requestRender("low")}),!(!this.state.visible&&!this.prevState.visible)&&this.requestRender("high")}afterDelete(){this.requestRender("high")}render(){if(this.deleted)return;const e=s.$t.copy(this.state.region);if(!this.state.visible)return()=>this.internal.renderCtx.erase(e,this.state.clearOverScan);const{renderCtx:n,handleError:r}=this.internal,i=s.C.XY.translate(s.$t.topLeft(this.state.region)),a=n.scissor(this.state.region,s.J.construct(this.state.clearOverScan),Er);try{for(const o of this.children)o.render({viewportScale:i})}catch(o){r(o,"Failed to render table")}finally{a()}return()=>this.internal.renderCtx.erase(e,this.state.clearOverScan)}requestRender(e){const{renderCtx:n}=this.internal;n.loop.set({key:`${Te.TYPE}-${this.key}`,render:this.render.bind(this),priority:e,canvases:Er})}}const ka={[Te.TYPE]:Te};class ne extends Ft.Observer{cleanup(){}}class fn extends ne{static TYPE="noop-boolean-sink";set(){}}const Jt={type:fn.TYPE,props:{},variant:"sink",valueType:"boolean"};class pn extends ne{static TYPE="noop-numeric-sink";set(){}}const cs={type:pn.TYPE,props:{},variant:"sink",valueType:"number"};class gn extends ne{static TYPE="noop-boolean-source";value(){return!1}}const qn={type:gn.TYPE,props:{},variant:"source",valueType:"boolean"};class mn extends ne{static TYPE="noop-numeric-source";value(){return 0}}const us={type:mn.TYPE,props:{},variant:"source",valueType:"number"};class yn extends ne{static TYPE="noop-string-source";value(){return""}}const hs={type:yn.TYPE,props:{},variant:"source",valueType:"string"};class vn extends ne{static TYPE="noop-status-source";value(){return{key:"noop",variant:"disabled",message:"unknown",time:s.n.now()}}}const Fn={type:vn.TYPE,props:{},variant:"source",valueType:"status"};class bn extends ne{static TYPE="noop-color-source";value(){return s.ir.ZERO}}const jt={type:bn.TYPE,props:{},variant:"source",valueType:"color"};class Sn extends ne{static TYPE="noop-series";value(){return[s.W.ZERO,new s.Vt([])]}}const ds={type:Sn.TYPE,props:{},variant:"source",valueType:"series"},Ra={[fn.TYPE]:fn,[pn.TYPE]:pn,[gn.TYPE]:gn,[mn.TYPE]:mn,[vn.TYPE]:vn,[bn.TYPE]:bn,[yn.TYPE]:yn,[Sn.TYPE]:Sn};class fs{type="noop";create(e){const n=Ra[e.type];return n==null?null:new n}}const Ma=d.z.instanceof(ArrayBuffer),tt=d.z.object({type:d.z.string(),variant:d.z.enum(["source","sink","source-transformer","sink-transformer"]),valueType:d.z.string(),props:d.z.any(),transfer:d.z.array(Ma).optional()}),re=tt.extend({variant:d.z.literal("source")}),Vt=tt.extend({variant:d.z.literal("sink")}),ps=tt.extend({variant:d.z.literal("source-transformer")}),gs=tt.extend({variant:d.z.literal("sink-transformer")}),gt=re.extend({valueType:d.z.literal("series")}),Wn=re.extend({valueType:d.z.literal("boolean")}),Gt=Vt.extend({valueType:d.z.literal("boolean")}),La=gs.extend({valueType:d.z.literal("boolean")}),Oa=ps.extend({valueType:d.z.literal("boolean")}),ms=re.extend({valueType:d.z.literal("number")}),ys=Vt.extend({valueType:d.z.literal("number")}),Hn=re.extend({valueType:d.z.literal("color")}),Jn=re.extend({valueType:d.z.literal("status")}),jn=re.extend({valueType:d.z.literal("string")});let Xt=class extends Ft.BaseObserver{props_=void 0;uProps_=void 0;constructor(e){super(),this.uProps_=e}get props(){if(this.props_==null){const e=this.schema.safeParse(this.uProps_);if(e.success)this.props_=e.data;else throw new p.P(`[BaseTelem] - expected props to be valid, but found the following errors:
2
- ${e.error.message}`)}return this.props_}cleanup(){}};class B extends Xt{}class Kt extends Xt{}class ue extends B{source_=void 0;get source(){if(this.source_==null)throw new p.P("[UnarySourceTransformer] - expected source to exist, but none was found.");return this.source_}value(){return this.transform(this.source.value())}onChange(e){return this.source.onChange(()=>{this.shouldNotify(this.source.value())&&e()})}setSources(e){this.source_=Object.values(e)[0]}shouldNotify(e){return!0}}class vs extends B{sources={};value(){const e=Object.fromEntries(Object.entries(this.sources).map(([n,r])=>[n,r.value()]));return this.transform(e)}setSources(e){this.sources={...this.sources,...e}}}class bs extends Xt{sinks={};get sink(){const[e]=Object.values(this.sinks);if(e==null)throw new p.P("[UnarySinkTransformer] - expected sink to exist, but none was found.");return e}set(...e){return this.sink.set(...this.transform(...e))}setSinks(e){this.sinks={...this.sinks,...e}}}const Vn=d.z.object({from:d.z.string(),to:d.z.string()}),Gn=d.z.object({connections:d.z.array(Vn),outlet:d.z.string(),segments:d.z.record(d.z.string(),re)});class Xn{type="pipeline";factory;constructor(e){this.factory=e}create(e){switch(e.type){case mt.TYPE:return new mt(e.props,this.factory);case yt.TYPE:return new yt(e.props,this.factory);default:return null}}}class mt extends B{static TYPE="source-pipeline";schema=Gn;sources={};get outlet(){const{outlet:e}=this.props,n=this.sources[e];if(n==null)throw new p.P(`[SourcePipeline] - expected source to exist at outlet '${e}', but none was found.`);return n}constructor(e,n){super(e);const{connections:r,segments:i}=this.props;Object.entries(i).forEach(([a,o])=>{const l=n.create(o);l!=null&&(this.sources[a]=l)}),r.forEach(({from:a,to:o})=>{const l=this.sources[a],u=this.sources[o];l==null||u==null||"setSources"in u&&u.setSources({[a]:l})})}value(){return this.outlet.value()}onChange(e){return this.outlet.onChange(e)}cleanup(){Object.values(this.sources).forEach(e=>e.cleanup?.())}}const Ss=(t,e)=>({variant:"source",props:e,type:mt.TYPE,valueType:t}),Kn=d.z.object({connections:d.z.array(Vn),inlet:d.z.string(),segments:d.z.record(d.z.string(),Vt)});class yt extends Kt{static TYPE="sink-pipeline";schema=Kn;sinks={};get inlet(){const{inlet:e}=this.props,n=this.sinks[e];if(n==null)throw new p.P(`[SinkPipeline] - expected source to exist at inlet '${e}', but none was found.`);return n}constructor(e,n){super(e);const{connections:r,segments:i}=this.props;Object.entries(i).forEach(([a,o])=>{const l=n.create(o);l!=null&&(this.sinks[a]=l)}),r.forEach(({from:a,to:o})=>{const l=this.sinks[a],u=this.sinks[o];l==null||u==null||"setSinks"in l&&l.setSinks({[o]:u})})}set(...e){return this.inlet.set(...e)}cleanup(){Object.values(this.sinks).forEach(e=>e.cleanup?.())}}const xs=(t,e)=>({variant:"sink",props:e,type:yt.TYPE,valueType:t}),Qn=d.z.object({channel:d.z.number().or(d.z.string())});class vt extends B{static TYPE="stream-channel-value";schema=Qn;client;removeStreamHandler=null;leadingBuffer=null;valid=!1;onStatusChange;constructor(e,n,r){super(n),this.client=e,this.onStatusChange=r?.onStatusChange}get testingOnlyLeadingBuffer(){return this.leadingBuffer}get testingOnlyValid(){return this.valid}cleanup(){this.removeStreamHandler?.(),this.valid=!1,this.leadingBuffer?.release(),this.leadingBuffer=null,this.removeStreamHandler=null}value(){return s.F.isZero(this.props.channel)||(this.valid||this.read(),this.leadingBuffer==null||this.leadingBuffer.length===0)?0:this.leadingBuffer.at(-1,!0)}async read(){try{this.valid=!0,this.removeStreamHandler?.();const e=await this.client.retrieveChannel(this.props.channel),n=r=>{const i=r.get(e.key);if(i==null)return;const a=i.series.at(-1);a!=null&&(a.acquire(),this.leadingBuffer?.release(),this.leadingBuffer=a),this.notify()};this.removeStreamHandler=await this.client.stream(n,[e.key]),this.notify()}catch(e){this.valid=!1,this.onStatusChange?.(s._r.fromException(e,"failed to stream channel value"))}}}const ws=async(t,e,n)=>{const r=await t.retrieveChannel(e),i=p.Rm.isCalculated(r);if(!n||r.isIndex)return{key:r.key,dataType:r.dataType,virtual:r.virtual,isCalculated:i};if(i){const a=await p.Rm.resolveCalculatedIndex(t.retrieveChannel.bind(t),r);if(a==null)throw new p.Ft("Failed to resolve calculated index");return{key:(await t.retrieveChannel(a)).key,dataType:s.r.TIMESTAMP,virtual:!1,isCalculated:i}}if(r.virtual)throw new p.Ft("cannot use virtual channels as a data source");return{key:r.index,dataType:s.r.TIMESTAMP,virtual:!1,isCalculated:i}},Ya=d.z.object({timeRange:s.w.z,channel:d.z.number().or(d.z.string()),useIndexOfChannel:d.z.boolean().optional().default(!1)});class bt extends B{static TYPE="series-source";client;schema=Ya;data=new s.Vt;valid=!1;channel=null;onStatusChange;constructor(e,n,r){super(n),this.client=e,this.onStatusChange=r?.onStatusChange}cleanup(){this.data.release(),this.valid=!1,this.channel=null}value(){const{channel:e,timeRange:n}=this.props;if(n.isZero||e===0)return[s.W.ZERO,this.data];this.valid||this.read();const{channel:r,data:i}=this;if(r==null)return[s.W.ZERO,this.data];let a=i.bounds;return r.dataType.equals(s.r.TIMESTAMP)&&(a=s.W.min([a,n.numericBounds])),[a,i]}async read(){try{this.valid=!0;const{timeRange:e,channel:n,useIndexOfChannel:r}=this.props;this.channel=await ws(this.client,n,r);const i=await this.client.read(e,this.channel.key);i.acquire(),this.data=i,this.notify()}catch(e){this.valid=!1,this.onStatusChange?.(s._r.fromException(e,"failed to read channel data"))}}}const $a=d.z.object({channel:d.z.number().or(d.z.string()),useIndexOfChannel:d.z.boolean().optional().default(!1),timeSpan:s.a.z,keepFor:s.a.z.optional()});class St extends B{static TYPE="dynamic-series-source";client;data=new s.Vt([]);now;onStatusChange;channel=null;stopStreaming;valid=!1;schema=$a;constructor(e,n,r,i=()=>s.n.now()){super(n),this.client=e,this.now=i,this.onStatusChange=r?.onStatusChange}value(){const{channel:e,timeSpan:n}=this.props;if(e===0)return[s.W.ZERO,this.data];this.valid||this.read();const{data:r,channel:i}=this,a=this.now();if(i!=null&&i.dataType.isVariable)return[s.W.ZERO,this.data];const o=r.series.filter(u=>u.timeRange.end.after(a.sub(n))).map(u=>u.bounds),l=s.W.max(o);return i!=null&&i.dataType.equals(s.r.TIMESTAMP)&&(l.lower=Math.max(l.lower,l.upper-Number(n.valueOf()))),[l,this.data]}async read(){try{this.valid=!0;const{channel:e,useIndexOfChannel:n,timeSpan:r}=this.props;this.channel=await ws(this.client,e,n);const i=this.now().spanRange(-r);if(!this.channel.virtual||this.channel.isCalculated){const o=await this.client.read(i,this.channel.key);o.acquire(),this.data.push(o)}this.stopStreaming?.();const a=o=>{if(this.channel==null)return;const l=o.get(this.channel.key);l!=null&&(l.acquire(),this.data.push(l),this.notify(),this.gcOutOfRangeData())};this.stopStreaming=await this.client.stream(a,[this.channel.key]),this.notify()}catch(e){this.valid=!1,this.onStatusChange?.(s._r.fromException(e,"failed to stream channel data"))}}gcOutOfRangeData(){const e=this.now().sub(this.props.keepFor??this.props.timeSpan),n=this.data.series.findIndex(r=>r.timeRange.end.before(e));n!==-1&&(this.data.series.splice(n,1).forEach(r=>r.release()),this.gcOutOfRangeData())}cleanup(){this.stopStreaming?.(),this.stopStreaming=void 0,this.data.release(),this.valid=!1}}const Da={[bt.TYPE]:bt,[St.TYPE]:St,[vt.TYPE]:vt};class Ts{type="remote";client;constructor(e){this.client=e}create(e,n){const r=Da[e.type];return r==null?null:new r(this.client,e.props,n)}}const Es=t=>({type:bt.TYPE,props:t,variant:"source",valueType:"series"}),Cs=t=>({type:St.TYPE,props:t,variant:"source",valueType:"series"}),Ps=t=>({type:vt.TYPE,props:t,variant:"source",valueType:"number"});class ks{type="static";create(e){switch(e.type){case xn.TYPE:return new xn(e.props);case xt.TYPE:return new xt(e.props);case wt.TYPE:return new wt(e.props);case Tt.TYPE:return new Tt(e.props);case Et.TYPE:return new Et(e.props);default:return null}}}const er=d.z.object({data:d.z.array(s.Yt),offsets:d.z.array(d.z.number()).optional().default([])});class xn extends B{data;schema=er;static TYPE="static-series";constructor(e){super(e),this.data=this.props.data.map((n,r)=>new s.I({data:n,dataType:s.r.FLOAT32,timeRange:s.w.ZERO,sampleOffset:this.props.offsets[r]??0}))}value(){return[s.W.max(this.data.map(n=>n.bounds)),this.data]}}const Rs=er.extend({rate:s.E.z,yOffset:d.z.number().optional().default(0),scroll:d.z.number().optional().default(0),startPosition:d.z.number().optional().default(0),scrollBounds:d.z.boolean().optional().default(!1)});class xt extends B{static TYPE="iterative-series";schema=Rs;position;interval;data;constructor(e){super(e),this.position=this.props.startPosition,this.start(this.props.rate),this.data=this.props.data.map((n,r)=>new s.I({data:n,dataType:s.r.FLOAT32,timeRange:s.w.ZERO,sampleOffset:this.props.offsets[r]??0}))}value(){const e=this.data.map(r=>r.slice(0,this.position));if(this.props.scrollBounds){const r=e[0].data[this.position-this.props.scroll<0?0:this.position-this.props.scroll],i=e[0].data[this.position-1];return[{lower:Number(r),upper:Number(i)},new s.Vt(e)]}return[s.W.max(e.map(r=>r.bounds)),new s.Vt(e)]}start(e){this.interval!=null&&clearInterval(this.interval),this.interval=setInterval(()=>{this.notify?.(),this.position++},e.period.milliseconds)}cleanup(){clearInterval(this.interval),this.interval=void 0}}const Ms=d.z.number();class wt extends B{static TYPE="static-numeric";schema=Ms;value(){return this.props}}const Ls=d.z.string();class Tt extends B{static TYPE="static-string";schema=Ls;value(){return this.props}}const Os=s.ir.crudeZ;class Et extends B{static TYPE="static-color";schema=Os;value(){return s.ir.construct(this.props)}}const _a=t=>({type:xn.TYPE,props:t,variant:"source",valueType:"series"}),za=t=>({type:xt.TYPE,props:t,variant:"source",valueType:"series"}),Aa=t=>({type:wt.TYPE,props:t,variant:"source",valueType:"number"}),Za=t=>({type:Tt.TYPE,props:t,variant:"source",valueType:"string"}),Ia=t=>({type:Et.TYPE,props:t,variant:"source",valueType:"color"});class Ys{type="transformer";create(e){switch(e.type){case Ee.TYPE:return new Ee(e.props);case Ce.TYPE:return new Ce(e.props);case Pe.TYPE:return new Pe(e.props);case ke.TYPE:return new ke(e.props);case Re.TYPE:return new Re(e.props);case Ct.TYPE:return new Ct(e.props);case Me.TYPE:return new Me(e.props);case Le.TYPE:return new Le(e.props)}return null}}const Na=d.z.object({truthy:d.z.number().optional().default(1),falsy:d.z.number().optional().default(0)}),$s=t=>({props:t,type:Ee.TYPE,variant:"sink",valueType:"boolean"});class Ee extends bs{static TYPE="boolean-numeric-converter-sink";static propsZ=Na;schema=Ee.propsZ;transform(...e){return e.map(n=>n?this.props.truthy:this.props.falsy)}}const tr=d.z.object({trueBound:s.W.bounds}),Ds=t=>({props:t,type:Ce.TYPE,variant:"source",valueType:"boolean"});class Ce extends ue{static TYPE="boolean-source";static propsZ=tr;schema=Ce.propsZ;curr=null;shouldNotify(e){const n=s.W.contains(this.props.trueBound,e)!==this.curr;return this.curr=s.W.contains(this.props.trueBound,e),n}transform(e){return this.curr=s.W.contains(this.props.trueBound,e),this.curr}}const _s=d.z.object({});class Pe extends vs{static TYPE="mean";static propsZ=_s;schema=Pe.propsZ;transform(e){return Object.values(e).reduce((n,r)=>n+r,0)/Object.keys(e).length}}const Ba=t=>({props:t,type:Pe.TYPE,variant:"source",valueType:"boolean"}),zs=d.z.object({trueVariant:s._r.variantZ.optional().default("success")});class ke extends ue{static TYPE="boolean-status";static propsZ=zs;schema=ke.propsZ;transform(e){return e.variant===this.props.trueVariant}}const Ua=t=>({props:t,type:ke.TYPE,variant:"source",valueType:"boolean"}),nr=d.z.object({precision:d.z.number().optional().default(2),prefix:d.z.string().optional().default(""),suffix:d.z.string().optional().default(""),notation:s.mr.notationZ.optional().default("standard")});class Re extends ue{static TYPE="stringify-number";static propsZ=nr;schema=Re.propsZ;transform(e){const{precision:n,prefix:r,suffix:i,notation:a}=this.props;return`${r}${s.mr.stringifyNumber(e,n,a)}${i}`}}const As=t=>({props:t,type:Re.TYPE,variant:"source",valueType:"string"}),rr=d.z.object({windowSize:d.z.number().optional().default(5)});class Ct extends ue{static TYPE="rolling-average";static propsZ=_s;schema=rr;values=[];transform(e){return this.props.windowSize<2?e:this.values.reduce((n,r)=>n+r,0)/this.values.length}shouldNotify(e){return this.props.windowSize<2?!0:(this.values.length>this.props.windowSize&&(this.values=[]),this.values.push(e),this.values.length===this.props.windowSize)}}const Zs=t=>({props:t,type:Ct.TYPE,variant:"source",valueType:"number"}),Is=d.z.object({gradient:s.ir.gradientZ});class Me extends ue{static TYPE="color-gradient";static propsZ=Is;schema=Me.propsZ;transform(e){return s.ir.fromGradient(this.props.gradient,e)}}const Ns=t=>({props:t,type:Me.TYPE,variant:"source",valueType:"color"}),Bs=d.z.object({scale:s.C.transform});class Le extends ue{static TYPE="scale-number";static propsZ=Bs;schema=Le.propsZ;transform(e){const{offset:n,scale:r}=this.props.scale;return e*r+n}}const Us=t=>({props:t,type:Le.TYPE,variant:"source",valueType:"number"});class sr{factories;type="compound";constructor(e){this.factories=e}add(e){this.factories=[...this.factories.filter(n=>n.type!==e.type),e]}create(e,n){for(const r of this.factories){const i=r.create(e,n);if(i!=null)return i}return null}}const qs=t=>{const e=[new Ys,new ks,new fs],n=new sr(e);return t!=null&&n.add(new Ts(t)),n.add(new Xn(n)),n};let Fs=class Ws{factory;key;parent;constructor(e,n){this.factory=e,this.key=s.$t$1.create(),this.parent=n}child(e,n){const r=new sr([...this.factory.factories,...p.t.toArray(e)]);return r.add(new Xn(r)),new Ws(r,n)}create(e,n){const r=this.factory.create(e,n);if(r==null)throw new p.lt(`Telemetry service could not find a source for type ${e.type}`);return r}};const nt="pluto-telem-context",Qt=t=>t.get(nt),Hs=(t,e)=>t.set(nt,e),Js=(t,e,n)=>{const r=Qt(t);if(r!=null&&n!=null&&r.key===n?.parent?.key)return n;const i=r.child(e,r);return t.set(nt,i),i};class js{spec;wrapped;prevProv;constructor(e,n,r){this.wrapped=e,this.spec=r,this.prevProv=n}shouldUpdate(e,n){return this.prevProv.key!==e.key||!p.m.equal(this.spec,n)}}class Cr extends js{value(){return this.wrapped.value()}cleanup(){this.wrapped.cleanup?.()}onChange(e){return this.wrapped.onChange(e)}}class Pr extends js{set(...e){this.wrapped.set(...e)}cleanup(){this.wrapped.cleanup?.()}}const F=(t,e,n,r)=>{const i=Qt(t);if(n instanceof Cr){if(!n.shouldUpdate(i,e))return n;n.cleanup?.()}return new Cr(i.create(e,r),i,e)},rt=(t,e,n,r)=>{const i=Qt(t);if(n instanceof Pr){if(!n.shouldUpdate(i,e))return n;n.cleanup?.()}return new Pr(i.create(e,r),i,e)},Vs=(t,e)=>t.dataType.isVariable||t.dataType.equals(s.r.UINT8)?t:(e==null&&t.dataType.equals(s.r.TIMESTAMP)&&(e=BigInt(t.data[0])),t.convert(s.r.FLOAT32,e)),qa=t=>t.isVariable||t.equals(s.r.UINT8)?t:s.r.FLOAT32,Gs=()=>({purgedSeries:0,purgedBytes:s.h.bytes(0)}),Xs={instrumentation:p.g.NOOP,staleEntryThreshold:s.a.seconds(20)};class Fa{data=[];props;constructor(e){this.props={...Xs,...e}}write(e){e.length!==0&&(e.series.forEach(n=>this.writeOne(Vs(n))),this.checkIntegrity(e))}dirtyRead(e){const n=this.data.filter(({data:o})=>o.timeRange.overlapsWith(e)).map(({data:o})=>o);if(n.length===0)return{series:new s.Vt([]),gaps:[e]};const r=n.map((o,l)=>l===0?s.w.ZERO:new s.w(n[l-1].timeRange.end,o.timeRange.start)).filter(o=>!o.isZero&&o.isValid),i=new s.w(e.start,n[0].timeRange.start),a=new s.w(n[n.length-1].timeRange.end,e.end);return i.isValid&&!i.isZero&&r.unshift(i),a.isValid&&!a.isZero&&r.push(a),{series:new s.Vt(n),gaps:r}}gc(){const{staleEntryThreshold:e}=this.props,n=Gs(),r=this.data.filter(i=>{const a=i.data.refCount>0||s.n.since(i.addedAt).lessThan(e);return a||(n.purgedBytes=n.purgedBytes.add(i.data.byteCapacity)),a});return n.purgedSeries=this.data.length-r.length,this.data=r,n}close(){this.data=[]}writeOne(e){const{instrumentation:{L:n}}=this.props;if(e.length===0)return;const r=s.W.buildInsertionPlan(this.data.map(u=>u.data.alignmentBounds),e.alignmentBounds);if(r===null)return n.debug("Found no viable insertion plan",{inserting:e.digest,cacheContents:this.data.map(u=>u.data.digest)});const{removeBefore:i,removeAfter:a,insertInto:o,deleteInBetween:l}=r;e=e.slice(i,e.data.length-a),e.length!==0&&this.data.splice(o,l,{data:e,addedAt:s.n.now()})}checkIntegrity(e){const{instrumentation:{L:n}}=this.props,r=this.data.map(a=>a.data.alignmentBounds);if(r.some((a,o)=>r.some((l,u)=>o===u?!1:s.W.overlapsWith(a,l))))throw n.debug("Cache is in an invalid state - bounds overlap!",()=>({write:e.series.map(a=>a.digest),cacheContents:this.data.map(a=>a.data.digest)})),new Error("Invalid state")}}const Wa=100,Ha=1e6,Ja=1e4,ja=100,Va=40;class Ga{props;counter=0;curr;avgRate=0;timeOfLastWrite;totalWrites=0;now=()=>s.n.now();constructor(e){this.props=e,this.curr=null,e.now!=null&&(this.now=e.now),this.timeOfLastWrite=this.now()}get length(){return this.curr?.length??0}get leadingBuffer(){return this.curr}write(e){const n=e.series.flatMap(r=>this._write(r));return{flushed:new s.Vt(n.flatMap(r=>r.flushed.series)),allocated:new s.Vt(n.flatMap(r=>r.allocated.series))}}allocate(e,n,r){this.counter++;const i=this.props.dataType.isVariable,a=this.props.dataType.equals(s.r.TIMESTAMP);return s.I.alloc({capacity:i?e*Va:e,dataType:qa(this.props.dataType),timeRange:r.range(s.n.MAX),sampleOffset:a?r.valueOf():0,glBufferUsage:"dynamic",alignment:n,key:`dynamic-${this.counter}`})}_write(e){const n=this.nextBufferSize(),r={flushed:new s.Vt([]),allocated:new s.Vt([])};if(this.curr==null)this.curr=this.allocate(n,e.alignment,this.now()),r.allocated.push(this.curr);else if(Math.abs(Number(this.curr.alignment+BigInt(this.curr.length)-e.alignment))>1){const u=this.now();this.curr.timeRange.end=u,r.flushed.push(this.curr),this.curr=this.allocate(n,e.alignment,u),r.allocated.push(this.curr)}const i=Vs(e,this.curr.sampleOffset),a=this.curr.write(i);if(a===e.length)return this.updateAvgRate(e),r;const o=this.now();this.curr.timeRange.end=o,r.flushed.push(this.curr),this.curr=this.allocate(n,e.alignment+BigInt(a),o),r.allocated.push(this.curr);const l=this._write(e.slice(a));return r.flushed.push(l.flushed),r.allocated.push(l.allocated),r}updateAvgRate(e){if(typeof this.props.dynamicBufferSize=="number")return;const n=e.length/this.now().span(this.timeOfLastWrite).seconds;this.totalWrites>0&&isFinite(n)&&n>0&&(this.avgRate=(this.avgRate*(this.totalWrites-1)+n)/this.totalWrites),this.totalWrites++,this.timeOfLastWrite=this.now()}nextBufferSize(){const{dynamicBufferSize:e}=this.props;if(typeof e=="number")return e;if(this.totalWrites<ja)return Ja;const n=s.nr.roundToNearestMagnitude(this.avgRate*e.seconds);return Math.round(Math.max(Math.min(n,Ha),Wa))}close(){this.curr=null}}class Xa{channel;closed=!1;ins;static;dynamic;constructor(e){this.channel=e.channel,this.ins=e.instrumentation??p.g.NOOP,this.static=new Fa(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}`),new s.Vt([]);const{flushed:n,allocated:r}=this.dynamic.write(e);return n.length>0&&this.static.write(n),r}get leadingBuffer(){return this.dynamic.leadingBuffer}writeStatic(e){if(this.closed)return this.ins.L.warn(`Ignoring attempted static write to a closed cache for channel ${this.channel.name}`);this.static.write(e)}read(e){return this.closed?(this.ins.L.warn(`Ignoring attempted dirty read from a closed cache for channel ${this.channel.name}`),{series:new s.Vt([]),gaps:[e]}):this.static.dirtyRead(e)}gc(){return this.closed?(this.ins.L.warn(`Ignoring attempted garbage collection on a closed cache for channel ${this.channel.name}`),{purgedSeries:0,purgedBytes:s.h.bytes(0)}):this.static.gc()}close(){this.closed=!0,this.dynamic.close(),this.static.close()}}const Ka=p.O$1.seconds(60);class Qa{props;cache=new Map;gcInterval;constructor(e){this.props={dynamicBufferSize:Ka,gcInterval:p.O$1.seconds(30),...Xs,...e},this.gcInterval=setInterval(()=>this.gc(),this.props.gcInterval.milliseconds)}async populateMissing(e){const{instrumentation:n,channelRetriever:r,dynamicBufferSize:i}=this.props,a=[];for(const l of e)this.cache.has(l)||a.push(l);if(a.length===0)return;(await r.retrieve(a)).forEach(l=>{if(this.cache.has(l.key))return;const u=new Xa({channel:l,dynamicBufferSize:i,instrumentation:n.child(`cache-${l.name}-${l.key}`)});this.cache.set(l.key,u)})}get(e){const n=this.cache.get(e);if(n!=null)return n;throw new p.lt(`cache entry for ${e} not found`)}gc(){const{instrumentation:{L:e}}=this.props;e.info("starting garbage collection");const n=Gs();this.cache.forEach(r=>{const i=r.gc();n.purgedSeries+=i.purgedSeries,n.purgedBytes=n.purgedBytes.add(i.purgedBytes)}),e.info("garbage collection complete",{purgedSeries:n.purgedSeries,purgedBytes:n.purgedBytes.toString()},!0)}close(){clearInterval(this.gcInterval),this.cache.forEach(e=>e.close()),this.cache.clear()}}class eo{args;debouncedRead;mu=s.wr.newMutex({requests:new Set,closed:!1});constructor(e){this.args={...e,instrumentation:e.instrumentation??p.g.NOOP,batchDebounce:e.batchDebounce??s.a.milliseconds(50),overlapThreshold:e.overlapThreshold??s.a.milliseconds(5)};const n=this.args.batchDebounce.milliseconds;this.debouncedRead=p.o(()=>void this.batchRead(),n)}async read(e,n){const{cache:r}=this.args;await r.populateMissing([n]);const i=r.get(n),{series:a,gaps:o}=i.read(e);if(o.length===0)return a;const{mu:l}=this;return await new Promise((u,c)=>{l.runExclusive(async()=>{l.closed||l.requests.add({channel:n,gaps:o,resolve:u,reject:c})}),this.debouncedRead()}),i.read(e).series}async batchRead(){const{readRemote:e,cache:n,overlapThreshold:r}=this.args,{mu:i}=this;await i.runExclusive(async()=>{const a=o=>i.requests.forEach(({resolve:l,reject:u})=>o==null?l():u(o));try{if(i.closed)return a();const o=[];i.requests.forEach(({channel:l,gaps:u})=>u.forEach(c=>{const h=o.find(f=>f.gap.equals(c,r));h==null?o.push({gap:c,channels:new Set([l])}):(h.channels.add(l),h.gap=s.w.max(h.gap,c))})),await Promise.all(o.map(async({gap:l,channels:u})=>{const c=await e(l,Array.from(u));u.forEach(h=>n.get(h).writeStatic(c.get(h)))})),a()}catch(o){a(o)}finally{i.requests.clear()}})}async close(){await this.mu.runExclusive(async()=>{this.mu.closed=!0})}}let to=class{props;mu=new as;listeners=new Map;streamerRunLoop=null;streamer=null;closed=!1;constructor(e){this.props={instrumentation:p.g.NOOP,...e,streamUpdateDelay:new s.a(e.streamUpdateDelay??s.a.seconds(5))}}async stream(e,n){const{cache:r,instrumentation:i}=this.props;return this.closed?()=>{}:(await r.populateMissing(n),await this.mu.runExclusive(async()=>{i.L.debug("adding stream handler",{keys:n}),this.listeners.set(e,{valid:!0,keys:new Set(n)});const a=new Map(n.map(o=>{const l=r.get(o);return[o,new s.Vt(p.t.toArray(l.leadingBuffer))]}));return e(a),await this.updateStreamer(),()=>this.removeStreamHandler(e)}))}removeStreamHandler(e){const{instrumentation:n}=this.props;this.mu.runExclusive(()=>{const r=this.listeners.get(e);r!=null&&(r.valid=!1)}),setTimeout(()=>{this.mu.runExclusive(async()=>{if(n.L.debug("removing stream handler"),this.listeners.delete(e))return await this.updateStreamer();n.L.warn("attempted to remove non-existent stream handler")})},this.props.streamUpdateDelay.milliseconds)}async updateStreamer(){if(this.closed)return;const{instrumentation:e}=this.props;try{const n=new Set;if(this.listeners.forEach(a=>a.keys.forEach(o=>n.add(o))),n.size===0){e.L.info("no keys to stream, closing streamer"),this.streamer?.close(),this.streamerRunLoop!=null&&await this.streamerRunLoop,this.streamer=null,e.L.info("streamer closed successfully");return}const r=Array.from(n);if(s.O.primitiveArrays(r,this.streamer?.keys??[])===s.O.EQUAL){e.L.debug("streamer keys unchanged",{keys:r});return}this.streamer==null&&(e.L.info("creating new streamer",{keys:r}),this.streamer=await this.props.openStreamer(r),this.streamerRunLoop=this.runStreamer(this.streamer)),e.L.debug("updating streamer",{prev:this.streamer.keys,next:r}),await this.streamer.update(r)}catch(n){throw e.L.error("failed to update streamer",{error:n}),n}}async runStreamer(e){const{cache:n,instrumentation:r}=this.props;try{for await(const i of e){const a=new Map;for(const o of i.keys){const l=i.get(o),c=n.get(o).writeDynamic(l);a.set(o,c)}a.size!==0&&this.listeners.forEach(({valid:o},l)=>o&&l(a))}}catch(i){throw r.L.error("streamer run loop failed",{error:i},!0),i}}async close(){const{instrumentation:e}=this.props;try{this.streamer?.close(),this.streamerRunLoop!=null&&await this.streamerRunLoop}catch(n){e.L.error("failed to close streamer",{error:n})}this.closed=!0}};class no{async retrieveChannel(){throw new p.Ft("NoopClient does not support retrieving channels")}async read(){return new s.Vt([])}async stream(){return async()=>{}}async close(){}}class ro{ins;cache;reader;streamer;channelRetriever;constructor({instrumentation:e,core:n}){this.ins=e,this.channelRetriever=n.channels.createDebouncedBatchRetriever(10),this.cache=new Qa({channelRetriever:this.channelRetriever,instrumentation:this.ins.child("cache")}),this.reader=new eo({cache:this.cache,readRemote:n.read.bind(n),instrumentation:this.ins.child("reader")}),this.streamer=new to({cache:this.cache,openStreamer:async r=>p.Pm.HardenedStreamer.open(n.openStreamer.bind(n),r),instrumentation:this.ins.child("streamer")})}async retrieveChannel(e){const n=await this.channelRetriever.retrieve([e]);if(n.length===0)throw new p.ke(`channel ${e} not found`);return n[0]}async read(e,n){return await this.reader.read(e,n)}async stream(e,n){return await this.streamer.stream(e,n)}async close(){this.ins.L.info("closing client"),await this.streamer.close(),await this.reader.close(),this.cache.close()}}const ir=d.z.object({});class Oe extends p.Composite{static TYPE="telem.Provider";static stateZ=ir;schema=Oe.stateZ;prevCore=null;client=null;afterUpdate(e){const{internal:n}=this,r=Ae(e),i=p.useErrorHandler(e);if(n.instrumentation=p.useInstrumentation(e,"telem").child("provider"),!(r!==this.prevCore||!e.wasSetPreviously(nt)))return;this.prevCore=r,this.client!=null&&i(async()=>{if(this.client==null)throw new Error("no client to close");await this.client.close()},"failed to close client"),this.client=r==null?new no:new ro({core:r,instrumentation:n.instrumentation});const o=qs(this.client),l=new Fs(o);Hs(e,l)}}const Ks={[Oe.TYPE]:Oe},so=Object.freeze(Object.defineProperty({__proto__:null,AbstractSink:Kt,AbstractSource:B,Base:Xt,BaseProvider:Oe,BooleanStatus:ke,CONTEXT_KEY:nt,ChannelData:bt,ColorGradient:Me,CompoundTelemFactory:sr,Context:Fs,FixedColorSource:Et,FixedNumber:wt,FixedString:Tt,IterativeSeries:xt,Mean:Pe,MultiSourceTransformer:vs,NoopFactory:fs,PipelineFactory:Xn,REGISTRY:Ks,RemoteFactory:Ts,RollingAverage:Ct,ScaleNumber:Le,SetPoint:Ee,SinkPipeline:yt,SourcePipeline:mt,StaticFactory:ks,StreamChannelData:St,StreamChannelValue:vt,StringifyNumber:Re,TransformerFactory:Ys,UnarySinkTransformer:bs,UnarySourceTransformer:ue,WithinBounds:Ce,booleanSinkSpecZ:Gt,booleanSinkTransformerSpecZ:La,booleanSourceSpecZ:Wn,booleanSourceTransformerSpecZ:Oa,booleanStatus:Ua,booleanStatusProps:zs,channelData:Es,colorGradient:Ns,colorGradientProps:Is,colorSourceSpecZ:Hn,connectionZ:Vn,createFactory:qs,fixedArray:_a,fixedColor:Ia,fixedColorSourcePropsZ:Os,fixedNumber:Aa,fixedNumberPropsZ:Ms,fixedSeriesPropsZ:er,fixedString:Za,fixedStringPropsZ:Ls,iterativeArray:za,iterativeSeriesPropsZ:Rs,mean:Ba,noopBooleanSinkSpec:Jt,noopBooleanSourceSpec:qn,noopColorSourceSpec:jt,noopNumericSinkSpec:cs,noopNumericSourceSpec:us,noopSeriesSourceSpec:ds,noopStatusSourceSpec:Fn,noopStringSourceSpec:hs,numberSinkSpecZ:ys,numberSourceSpecZ:ms,providerStateZ:ir,rollingAverage:Zs,rollingAverageProps:rr,scaleNumber:Us,scaleNumberProps:Bs,seriesSourceSpecZ:gt,setContext:Hs,setpoint:$s,sinkPipeline:xs,sinkPipelinePropsZ:Kn,sinkSpecZ:Vt,sinkTransformerSpecZ:gs,sourcePipeline:Ss,sourcePipelinePropsZ:Gn,sourceSpecZ:re,sourceTransformerSpecZ:ps,specZ:tt,statusSourceSpecZ:Jn,streamChannelData:Cs,streamChannelValue:Ps,streamChannelValuePropsZ:Qn,stringSourceSpecZ:jn,stringifyNumber:As,stringifyNumberProps:nr,useChildContext:Js,useContext:Qt,useSink:rt,useSource:F,withinBounds:Ds,withinBoundsProps:tr},Symbol.toStringTag,{value:"Module"})),Qs=d.z.object({authority:s.ar.authorityZ.optional(),valid:d.z.boolean().optional()}).default({authority:void 0,valid:!1}),ei=d.z.object({triggered:d.z.boolean(),status:s._r.statusZ(Qs),sink:Gt.optional().default(Jt),source:Jn.optional().default(Fn)});class wn extends p.Leaf{static TYPE="Chip";schema=ei;afterUpdate(e){const{internal:n}=this,{sink:r,source:i}=this.state;n.source=F(e,i,n.source),n.sink=rt(e,r,n.sink),this.state.triggered&&!this.prevState.triggered&&n.sink.set(this.state.status.details?.authority!==s.ar.ABSOLUTE_AUTHORITY),this.updateEnabledState(),n.stopListening?.(),n.stopListening=n.source.onChange(()=>this.updateEnabledState())}updateEnabledState(){const e=this.internal.source.value();p.m.equal(e,this.state.status)||this.setState(n=>({...n,status:e,triggered:!1}))}afterDelete(){this.internal.stopListening(),this.internal.source.cleanup?.(),this.internal.sink.cleanup?.()}render(){}}const ti=d.z.object({}),kr="control-state-provider",ni=p.Bm.stateZ.extend({subjectColor:s.ir.colorZ});class We extends p.Composite{static TYPE="StateProvider";schema=ti;colors=new Map;tracker;disconnectTrackerChange;obs=new Ft.Observer;static use(e){return e.get(kr)}afterUpdate(e){const{internal:n}=this;n.instrumentation=p.useInstrumentation(e,"control-state");const r=p.use(e);n.palette=r.colors.visualization.palettes.default,n.defaultColor=r.colors.gray.l8;const i=Ae(e);if(n.client!=null&&i===n.client)return;n.client=i,e.set(kr,this),p.useErrorHandler(e)(async()=>{await this.maybeCloseTracker(),n.client!=null&&(this.internal.instrumentation.L.debug("starting state tracker"),await this.openTracker(n.client))},"failed to open control state tracker")}async maybeCloseTracker(){this.tracker!=null&&(this.internal.instrumentation.L.debug("stopping state tracker"),this.disconnectTrackerChange?.(),await this.tracker.close(),this.tracker=void 0)}afterDelete(e){p.useErrorHandler(e)(async()=>{await this.maybeCloseTracker()},"failed to close control state tracker")}onChange(e){return this.obs.onChange(e)}get(e){return Array.isArray(e)?s.c.unique(e).map(n=>this.getOne(n)).filter(n=>n!=null):this.getOne(e)}getOne(e){if(this.tracker==null)return;const n=this.tracker.states.get(e);if(n!=null)return{...n,subjectColor:this.colors.get(n.subject.key)??this.internal.defaultColor}}async openTracker(e){const{internal:n}=this,{instrumentation:r}=n;try{this.tracker=await e.control.openStateTracker()}catch{r.L.error("failed to open state tracker");return}this.disconnectTrackerChange?.(),this.disconnectTrackerChange=this.tracker.onChange(i=>{if(r.L.debug("transfer",{transfers:i.map(a=>p.Bm.transferString(a))}),this.tracker==null)throw new p.lt("tracker is null inside it's own onChange callback!");this.updateColors(this.tracker),this.obs.notify(i)})}updateColors(e){const n=e.subjects(),r=n.map(o=>o.key),i=Array.from(this.colors.values());this.colors.forEach((o,l)=>!r.includes(l)&&this.colors.delete(l));const{palette:a}=this.internal;n.forEach(o=>{if(this.colors.has(o.key))return;const l=a.find(u=>!i.includes(u))??a[0];this.colors.set(o.key,l),i.push(l)})}}const ri=["acquired","released","overridden","failed"],si=d.z.enum(ri),ii=d.z.object({name:d.z.string(),authority:d.z.number().default(0),acquireTrigger:d.z.number(),status:si.optional(),needsControlOf:p.Rm.keyZ.array().optional().default([])});class Tn extends p.Composite{static TYPE="Controller";schema=ii;registry=new Map;writer;afterUpdate(e){const{internal:n}=this;n.instrumentation=p.useInstrumentation(e),n.addStatus=p.useAdder(e),n.runAsync=p.useErrorHandler(e),(n.prevTrigger==null||Math.abs(this.state.acquireTrigger-n.prevTrigger)>1)&&(n.prevTrigger=this.state.acquireTrigger);const r=Ae(e),i=We.use(e);n.stateProv=i,n.telemCtx=Js(e,this,n.telemCtx),n.client=r,n.runAsync(async()=>{n.client==null&&await this.release(),this.state.acquireTrigger>n.prevTrigger?await this.acquire():this.state.acquireTrigger<n.prevTrigger&&await this.release()},"failed to acquire control")}afterDelete(){const{internal:e}=this;e.runAsync(async()=>await this.release(),"failed to release control")}async updateNeedsControlOf(){const{client:e}=this.internal;if(e==null)return;const n=new Set([]);for(const i of this.registry.keys())(await i.needsControlOf(e)).forEach(o=>o!==0&&n.add(o));const r=Array.from(n);s.O.unorderedPrimitiveArrays(this.state.needsControlOf,r)!==s.O.EQUAL&&this.setState(i=>({...i,needsControlOf:r}))}async acquire(){this.internal.prevTrigger=this.state.acquireTrigger;const{client:e,addStatus:n}=this.internal;if(e==null)return n({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 n({message:`Cannot acquire control on ${this.state.name} because there are no channels to control.`,variant:"warning"});const i=p.S.now().sub(s.a.milliseconds(1));this.writer=await e.openWriter({start:i,channels:r,controlSubject:{key:this.key,name:this.state.name},authorities:this.state.authority,enableAutoCommit:!0}),this.setState(a=>({...a,status:"acquired"}))}catch(r){if(this.setState(i=>({...i,status:"failed"})),!(r instanceof Error))throw r;n({variant:"error",message:`${this.state.name} failed to acquire control`,description:r.message})}}async release(){this.internal.prevTrigger=this.state.acquireTrigger;try{await this.writer?.close()}catch(e){this.internal.addStatus({message:`${this.state.name} failed to release control: ${e.message}`,variant:"error"})}finally{this.setState(e=>({...e,status:"released"})),this.writer=void 0}}async set(e){this.writer==null&&await this.acquire(),await this.writer?.write(e)}async setAuthority(e,n){this.writer==null&&await this.acquire(),await this.writer?.setAuthority(Object.fromEntries(e.map(r=>[r,n])))}async releaseAuthority(e){this.writer==null&&await this.acquire(),await this.writer?.setAuthority(Object.fromEntries(e.map(n=>[n,this.state.authority])))}deleteTelem(e){this.registry.delete(e),this.updateNeedsControlOf()}create(e){const{internal:n}=this,i=(()=>{switch(e.type){case Pt.TYPE:{const a=new Pt(this,n.runAsync,e.props);return this.registry.set(a,null),a}case Rt.TYPE:{const a=new Rt(this,this.internal.stateProv,e.props);return this.registry.set(a,null),a}case kt.TYPE:return new kt(this,n.runAsync,e.props);default:return null}})();return i!=null&&this.updateNeedsControlOf(),i}}const ai=d.z.object({channel:d.z.number()});class Pt extends Kt{static TYPE="controlled-numeric-telem-sink";controller;runAsync;schema=ai;constructor(e,n,r){super(r),this.controller=e,this.runAsync=n}invalidate(){}cleanup(){this.controller.deleteTelem(this)}async needsControlOf(e){if(this.props.channel===0)return[];const n=await e.channels.retrieve(this.props.channel),r=[n.key];return n.index!==0&&r.push(n.index),r}set(...e){this.runAsync(async()=>{const{client:n}=this.controller.internal;if(n==null)throw new p.bm("No cluster connected");if(this.props.channel===0)throw new p.P("No command channel specified for actuator");const r=await n.channels.retrieve(this.props.channel),i={[r.key]:e};if(r.index!==0){const a=await n.channels.retrieve(r.index),o=p.S.now();i[a.key]=Array.from({length:e.length},(l,u)=>o.add(s.a.nanoseconds(u)))}await this.controller.set(i)},"Failed to command channel")}}const io=t=>({type:Pt.TYPE,props:t,variant:"sink",valueType:"number"}),oi=d.z.object({authority:d.z.number().default(p.Bm.ABSOLUTE_AUTHORITY),channel:d.z.number()});class kt extends Kt{static TYPE="acquire-channel-control";controller;runAsync;schema=oi;constructor(e,n,r){super(r),this.controller=e,this.runAsync=n}cleanup(){this.controller.deleteTelem(this)}async needsControlOf(e){const n=await e.channels.retrieve(this.props.channel),r=[n.key];return n.index!==0&&r.push(n.index),r}set(e){this.runAsync(async()=>{const{controller:n}=this,{client:r}=n.internal;if(r==null)return;const i=await r.channels.retrieve(this.props.channel),a=[i.key];i.index!==0&&a.push(i.index),e?await this.controller.setAuthority(a,this.props.authority):await this.controller.releaseAuthority(a)},"failed to set channel authority")}}const ao=t=>({type:kt.TYPE,props:t,variant:"sink",valueType:"boolean"}),li=d.z.object({channel:d.z.number()}),oo=d.z.object({valid:d.z.boolean(),color:s.ir.colorZ.optional(),authority:d.z.number()});class Rt extends B{static TYPE="controlled-status-source";prov;valid=!1;stopListening;controller;schema=li;constructor(e,n,r){super(r),this.prov=n,this.controller=e}async needsControlOf(){return[]}maybeRevalidate(){if(this.valid)return;const{channel:e}=this.props;this.stopListening?.();const n=s.ar.filterTransfersByChannelKey(e);this.stopListening=this.prov.onChange(r=>{n(r).length!==0&&this.notify?.()}),this.valid=!0}value(){this.maybeRevalidate();const e=p.S.now();if(this.props.channel===0)return{key:this.controller.key,variant:"disabled",message:"No Channel",time:e,details:{valid:!1,authority:0}};const n=this.prov.get(this.props.channel);return n==null?{key:this.controller.key,variant:"disabled",message:"Uncontrolled",time:e,details:{valid:!0,color:void 0,authority:0}}:{key:n.subject.key,variant:n.subject.key===this.controller.key?"success":"error",message:`Controlled by ${n.subject.name}`,time:e,details:{valid:!0,color:n.subjectColor,authority:n.authority}}}cleanup(){this.controller.deleteTelem(this),this.stopListening?.()}}const lo=t=>({type:Rt.TYPE,props:t,variant:"source",valueType:"status"}),ci=d.z.object({color:s.ir.colorZ.optional()}).default({color:void 0}),ui=d.z.object({statusSource:Jn.optional().default(Fn),colorSource:Hn.optional().default(jt),status:s._r.statusZ(ci),color:s.ir.colorZ.optional()});class En extends p.Leaf{static TYPE="Indicator";schema=ui;stopListeningStatus;stopListeningColor;afterUpdate(e){const{internal:n}=this,{statusSource:r,colorSource:i}=this.state;n.statusSource=F(e,r,n.statusSource),n.colorSource=F(e,i,n.colorSource),this.updateState(),this.stopListeningStatus?.(),this.stopListeningColor?.(),this.stopListeningStatus=n.statusSource.onChange(this.updateState.bind(this)),this.stopListeningColor=n.colorSource.onChange(this.updateState.bind(this))}afterDelete(){this.internal.statusSource.cleanup?.(),this.internal.colorSource.cleanup?.()}render(){}updateState(){const e=this.internal.colorSource.value(),n=this.internal.statusSource.value();s.ir.equals(e,this.state.color)&&n.message===this.state.status.message||this.setState(r=>({...r,color:e,status:n}))}}const hi=d.z.object({needsControlOf:p.Rm.keyZ.array(),states:ni.array()});class Cn extends p.Leaf{static TYPE="Legend";schema=hi;afterUpdate(e){const{internal:n}=this;n.stateProv=We.use(e);const r=this.state.needsControlOf;n.disconnectStateProv?.();const i=s.ar.filterTransfersByChannelKey(...r),a=n.stateProv.get(r);this.setState(o=>({...o,states:a})),n.disconnectStateProv=n.stateProv.onChange(o=>{if(i(o).length===0)return;const l=n.stateProv.get(r);this.setState(u=>({...u,states:l}))})}afterDelete(){const{internal:e}=this;e.disconnectStateProv?.()}render(){}}const co={[Tn.TYPE]:Tn,[We.TYPE]:We,[En.TYPE]:En,[wn.TYPE]:wn,[Cn.TYPE]:Cn},di=["fire","momentary","pulse"],uo=d.z.enum(di),fi=d.z.object({trigger:d.z.number(),sink:Gt.optional().default(Jt),mode:uo.optional().default("fire")}),pi=2,gi=1;class Pn extends p.Leaf{static TYPE="Button";schema=fi;afterUpdate(e){const{sink:n,mode:r,trigger:i}=this.state,{internal:a}=this;a.prevTrigger??=i,a.sink=rt(e,n,a.sink);const o=a.prevTrigger;a.prevTrigger=i;const l=i===o+pi;i===o+gi?r=="fire"?this.internal.sink.set(!0):r=="momentary"&&this.internal.sink.set(!1):l&&(r=="momentary"?this.internal.sink.set(!0):r=="pulse"&&this.internal.sink.set(!0,!1))}afterDelete(){this.internal.sink.cleanup?.()}}const ho={[Pn.TYPE]:Pn},Rr=`#version 300 es
3
- precision lowp float;
4
-
5
- uniform lowp vec4 u_color;
6
- out vec4 fragColor;
7
-
8
- void main(void) {
9
- fragColor = u_color;
10
- }
11
- `,fo=`#version 300 es
12
-
13
- // Copyright 2025 Synnax Labs, Inc.
14
- //
15
- // Use of this software is governed by the Business Source License included in the file
16
- // licenses/BSL.txt.
17
- //
18
- // As of the Change Date specified in that file, in accordance with the Business Source
19
- // License, use of this software will be governed by the Apache License, Version 2.0,
20
- // included in the file licenses/APL.txt.
21
-
22
- in mediump float a_x;
23
- in mediump float a_y;
24
- in mediump vec2 a_translate;
25
-
26
- uniform mediump vec2 u_scale_aggregate;
27
- uniform mediump vec2 u_offset_aggregate;
28
-
29
- void main(void) {
30
- gl_Position = vec4((u_scale_aggregate * vec2(a_x, a_y) + u_offset_aggregate) + a_translate, 0.0, 1.0);
31
- }
32
- `,po=`#version 300 es
33
-
34
- // Copyright 2025 Synnax Labs, Inc.
35
- //
36
- // Use of this software is governed by the Business Source License included in the file
37
- // licenses/BSL.txt.
38
- //
39
- // As of the Change Date specified in that file, in accordance with the Business Source
40
- // License, use of this software will be governed by the Apache License, Version 2.0,
41
- // included in the file licenses/APL.txt.
42
-
43
- in mediump float a_x;
44
- in mediump uint a_y;
45
- in mediump vec2 a_translate;
46
-
47
- uniform mediump vec2 u_scale_aggregate;
48
- uniform mediump vec2 u_offset_aggregate;
49
-
50
- void main(void) {
51
- gl_Position = vec4((u_scale_aggregate * vec2(a_x, float(a_y)) + u_offset_aggregate) + a_translate, 0.0, 1.0);
52
- }
53
- `,mi=d.z.object({x:gt,y:gt,label:d.z.string().optional(),color:s.ir.colorZ,strokeWidth:d.z.number().default(1),downsample:d.z.number().min(1).max(50).optional().default(1),visible:d.z.boolean().optional().default(!0)}),go=(t,e,n)=>t===-1||e===-1||t>=n.series.length?NaN:Number(n.series[t].at(e)),mo=s.a.milliseconds(2);s.J.NAN,s.J.NAN,s.ir.ZERO,s.W.ZERO;const yo=(t,e)=>e.equals(s.r.UINT8)?t.UNSIGNED_BYTE:t.FLOAT;class Mr extends p.GLProgram{translationBufferCache=new Map;constructor(e,n,r){super(e,n,r),this.translationBufferCache=new Map}bindState({strokeWidth:e,color:n}){return this.uniformColor("u_color",n),this.attrStrokeWidth(e)}bindScale(e,n){const r=s.J.scale(e.scale,n.scale),i=s.J.translate(s.J.scale(n.scale,e.offset),n.offset);this.uniformXY("u_scale_aggregate",r),this.uniformXY("u_offset_aggregate",i)}draw({x:e,y:n,count:r,downsample:i,xOffset:a,yOffset:o},l,u,c){const{gl:h}=this.renderCtx;this.bindAttrBuffer("x",e.glBuffer,i,a,u),this.bindAttrBuffer("y",n.glBuffer,i,o,c),h.drawArraysInstanced(h.LINE_STRIP,0,r/i,l)}bindAttrBuffer(e,n,r,i=0,a){const{gl:o}=this.renderCtx;o.bindBuffer(o.ARRAY_BUFFER,n);const l=o.getAttribLocation(this.prog,`a_${e}`),u=yo(o,a),c=a.density.valueOf();a.equals(s.r.UINT8)?o.vertexAttribIPointer(l,1,u,c*r,c*i):o.vertexAttribPointer(l,1,u,!1,c*r,c*i),o.enableVertexAttribArray(l)}getAndBindTranslationBuffer(e){const{gl:n}=this.renderCtx,r=`${this.renderCtx.aspect}:${e}`,i=this.translationBufferCache.get(r);if(i!=null)return n.bindBuffer(n.ARRAY_BUFFER,i.glBuffer),i;const a=n.createBuffer();if(a==null)throw new p.lt("Failed to create buffer from WebGL context");const o=bo(this.renderCtx.aspect,e);n.bindBuffer(n.ARRAY_BUFFER,a),n.bufferData(n.ARRAY_BUFFER,o,n.DYNAMIC_DRAW);const l={glBuffer:a,jsBuffer:o};return this.translationBufferCache.set(r,l),l}attrStrokeWidth(e){const{gl:n}=this.renderCtx,{jsBuffer:r}=this.getAndBindTranslationBuffer(e),i=n.getAttribLocation(this.prog,"a_translate");return n.vertexAttribPointer(i,2,n.FLOAT,!1,0,0),n.enableVertexAttribArray(i),n.vertexAttribDivisor(i,1),r.length/2}}class xe{static CONTEXT_KEY="pluto-line-gl-program";uint8HybridProgram;float32Program;constructor(e){this.uint8HybridProgram=new Mr(e,po,Rr),this.float32Program=new Mr(e,fo,Rr)}get gl(){return this.uint8HybridProgram.renderCtx.gl}getProgram(e){return e.equals(s.r.UINT8)?this.uint8HybridProgram:this.float32Program}static create(e,n){const r=new xe(n);return e.set(xe.CONTEXT_KEY,r),r}static use(e){const n=e.get(xe.CONTEXT_KEY);if(n==null)throw new p.lt("GLProgram not found");return n}}class Mt extends p.Leaf{static TYPE="line";schema=mi;afterUpdate(e){const{internal:n}=this,r={onStatusChange:p.useAdder(e)};n.xTelem=F(e,this.state.x,n.xTelem,r),n.yTelem=F(e,this.state.y,n.yTelem,r),n.instrumentation=p.useInstrumentation(e,"line"),n.lineCtx=xe.use(e),n.requestRender=Ht(e),n.stopListeningXTelem?.(),n.stopListeningYTelem?.(),n.stopListeningXTelem=n.xTelem.onChange(()=>n.requestRender("data")),n.stopListeningYTelem=n.yTelem.onChange(()=>n.requestRender("data")),n.requestRender("layout")}afterDelete(){const{internal:e}=this;e.xTelem.cleanup?.(),e.yTelem.cleanup?.(),e.requestRender("layout")}xBounds(){return this.internal.xTelem.value()[0]}yBounds(){return this.internal.yTelem.value()[0]}findByXValue(e,n){const{xTelem:r,yTelem:i}=this.internal,[,a]=r.value();let[o,l]=[-1,-1];a.series.find((S,R)=>{const L=S.binarySearch(n),k=L>=0&&L<S.length;return k&&([o,l]=[L,R]),k});const{key:u}=this,{color:c,label:h}=this.state,f={key:u,color:c,label:h,position:{x:0,y:0},value:{x:NaN,y:NaN},bounds:{lower:0,upper:0}};if(o===-1||l===-1||!this.state.visible)return f;const g=a.series[l];f.value.x=go(l,o,a);const[,v]=i.value(),w=v.series.find(S=>s.W.contains(S.alignmentBounds,g.alignment+BigInt(o)));if(w==null)return f;const b=Number(w.alignment-g.alignment);return f.value.y=Number(w.at(o-b)),f.bounds={...w.bounds},f.position={x:e.dataToDecimalScale.x.pos(f.value.x),y:e.dataToDecimalScale.y.pos(f.value.y)},f}render(e){if(this.deleted||!this.state.visible)return;const{downsample:n}=this.state,{xTelem:r,yTelem:i,lineCtx:a}=this.internal,{dataToDecimalScale:o,exposure:l}=e,[[,u],[,c]]=[r.value(),i.value()];if(u.updateGLBuffer(a.gl),c.updateGLBuffer(a.gl),u.length===0||c.length===0)return;const h=a.getProgram(c.dataType),f=Co(u,c,l,n,mo);this.internal.instrumentation.L.debug("render",()=>({key:this.key,downsample:n,scale:o.transform,props:e.region,ops:Po(f)}));const g=h.setAsActive(),v=h.bindState(this.state),w=h.renderCtx.scaleRegion(e.region).transform;f.forEach(b=>{const S=To(o,b).transform;h.bindScale(S,w),h.draw(b,v,u.dataType,c.dataType)}),g()}}const vo=5e3,bo=(t,e)=>wo(xo(t),e).map((n,r)=>Math.floor(r/So)*(1/(vo*t))*n),So=5,xo=t=>new Float32Array([0,0,0,t,0,-t,1,0,-1,0]),wo=(t,e)=>{const n=new Float32Array(t.length*e);for(let r=0;r<e;r++)n.set(t,r*t.length);return n},To=(t,e)=>t.translate(t.x.dim(Number(e.x.sampleOffset)),t.y.dim(Number(e.y.sampleOffset))),Eo={[Mt.TYPE]:Mt},Co=(t,e,n,r,i)=>{if(t.series.length===0||e.series.length===0)return[];const a=[];return t.series.forEach(o=>e.series.forEach(l=>{if(!ko(o,l,i))return;let u=0,c=0;o.alignment<l.alignment?u=Number(l.alignment-o.alignment):l.alignment<o.alignment&&(c=Number(o.alignment-l.alignment));const h=Math.min(o.length-u,l.length-c);if(h===0)return;const f=s.R(Math.round(n*4*h),r,51);a.push({x:o,y:l,xOffset:u,yOffset:c,count:h,downsample:f})})),a},Po=t=>t.map(e=>({...e,x:e.x.digest,y:e.y.digest})),ko=(t,e,n)=>{const r=t.timeRange.overlapsWith(e.timeRange,n),i=s.W.overlapsWith(t.alignmentBounds,e.alignmentBounds);return r&&i},ar=d.z.object({dpr:d.z.number(),region:s.$t.box,bootstrap:d.z.boolean().optional().default(!1),bootstrapped:d.z.boolean().optional().default(!1),glCanvas:d.z.any().optional(),upper2dCanvas:d.z.any().optional(),lower2dCanvas:d.z.any().optional(),os:s.S.osZ});class Lt extends p.Composite{static TYPE="Canvas";schema=ar;renderCtx=null;afterUpdate(e){if(this.renderCtx==null){if(!this.state.bootstrap)return;const{glCanvas:n,lower2dCanvas:r,upper2dCanvas:i,os:a}=this.state;if(n==null||r==null||i==null)throw new p.lt("[vis.worker.Canvas] - expected render context bootstrap to include all canvases");this.renderCtx=p.Context.create(e,n,r,i,a),xe.create(e,this.renderCtx),this.setState(o=>({...o,bootstrap:!1,bootstrapped:!0,glCanvas:void 0,lower2dCanvas:void 0,upper2dCanvas:void 0}))}else this.renderCtx.update(e);this.renderCtx.resize(this.state.region,this.state.dpr)}}const yi={[Lt.TYPE]:Lt},Ro=Object.freeze(Object.defineProperty({__proto__:null,Canvas:Lt,REGISTRY:yi,canvasStateZ:ar},Symbol.toStringTag,{value:"Module"})),or=d.z.object({position:s.J.xy,zoom:d.z.number(),region:s.$t.box,clearOverScan:s.J.crudeZ.optional().default(10),visible:d.z.boolean().optional().default(!0)}),ct=["upper2d","lower2d"];class le extends p.Composite{static TYPE="Diagram";static stateZ=or;schema=le.stateZ;afterUpdate(e){this.internal.renderCtx=p.Context.use(e),this.internal.handleError=p.useErrorHandler(e),Wt(e,()=>{this.state.visible&&this.requestRender("low")}),!(!this.state.visible&&!this.prevState.visible)&&(this.internal.viewportScale=s.C.XY.magnify(s.J.construct(this.state.zoom)).translate(s.$t.topLeft(this.state.region)).translate(this.state.position),this.requestRender("high"))}afterDelete(){this.requestRender("high")}render(){if(this.deleted)return;const{renderCtx:e,handleError:n,viewportScale:r}=this.internal,i=s.$t.construct(this.state.region);if(!this.state.visible)return()=>e.erase(i,this.state.clearOverScan,...ct);const a=e.scissor(i,s.J.ZERO,ct);try{this.children.forEach(l=>l.render?.({viewportScale:r}))}catch(l){n(l,"failed to render diagram")}finally{a()}const o=s.$t.copy(this.state.region);return()=>{e.lower2d.fillStyle=s.ir.hex(s.ir.BLACK),e.lower2d.fillRect(...s.J.couple(s.$t.topLeft(o)),s.$t.width(o),s.$t.height(o)),e.erase(o,this.state.clearOverScan,...ct)}}requestRender(e){const{renderCtx:n}=this.internal;n.loop.set({key:`${le.TYPE}-${this.key}`,render:this.render.bind(this),priority:e,canvases:ct})}}const vi={[le.TYPE]:le},Mo=Object.freeze(Object.defineProperty({__proto__:null,Diagram:le,REGISTRY:vi,diagramStateZ:or},Symbol.toStringTag,{value:"Module"})),bi=d.z.object({enabled:d.z.boolean(),source:Wn.optional().default(qn)});class kn extends p.Leaf{static TYPE="Light";schema=bi;afterUpdate(e){this.internal.addStatus=p.useOptionalAdder(e);const{source:n}=this.state,{internal:r}=this;this.internal.source=F(e,n,this.internal.source),r.stopListening?.(),r.stopListening=r.source.onChange(()=>this.updateEnabledState())}updateEnabledState(){const e=this.internal.source.value();e!==this.state.enabled&&this.setState(n=>({...n,enabled:e}))}afterDelete(){this.internal.stopListening(),this.internal.source.cleanup?.()}}const Lo={[kn.TYPE]:kn},Oo=d.object({request:d.string(),bounds:d.record(d.string(),s.W.bounds)}),Si=d.object({request:d.string(),response:Oo});class Ot extends p.Leaf{static TYPE="Bounds";schema=Si;afterUpdate(e){this.state.request!==this.prevState.request&&this.setState(n=>({...n,response:{request:n.request,bounds:this.internal.getBounds()}}))}render(e){this.internal.getBounds=e.getBounds}}const xi=d.z.object({key:d.z.string(),size:d.z.number(),order:d.z.number(),loc:s.K.outer});d.z.record(d.z.string(),xi);const ie=(t,e)=>Object.values(e).filter(({loc:n})=>n===t).sort((n,r)=>r.order-n.order),Yo=(t,e,n)=>{const r=e[t];if(r==null)return s.J.ZERO;const i=s.K.construct(r.loc),a=ie(i,e),o=s.K.construct(s.g.swap(s.K.direction(i))),l=ie(o,e),u=a.findIndex(({key:f})=>f===t),c=a.slice(0,u).reduce((f,{size:g})=>f+g,0),h=l.reduce((f,{size:g})=>f+g,0);switch(i){case"left":return s.J.translate(s.$t.topLeft(n),[c,h]);case"right":return s.J.translate(s.$t.topRight(n),[c-r.size,h]);case"top":return s.J.translate(s.$t.topLeft(n),[h,c]);default:return s.J.translate(s.$t.bottomLeft(n),[h,-c-r.size])}},$o=(t,e)=>{const n=ie("left",t),r=ie("right",t),i=ie("top",t),a=ie("bottom",t),o=n.reduce((h,{size:f})=>h+f,0),l=r.reduce((h,{size:f})=>h+f,0),u=i.reduce((h,{size:f})=>h+f,0),c=a.reduce((h,{size:f})=>h+f,0);return s.$t.construct(s.J.translate(s.$t.topLeft(e),{x:o,y:u}),s.$t.width(e)-o-l,s.$t.height(e)-u-c)};function ft(t,e){return t==null||e==null?NaN:t<e?-1:t>e?1:t>=e?0:NaN}function Do(t,e){return t==null||e==null?NaN:e<t?-1:e>t?1:e>=t?0:NaN}function lr(t){let e,n,r;t.length!==2?(e=ft,n=(l,u)=>ft(t(l),u),r=(l,u)=>t(l)-u):(e=t===ft||t===Do?t:_o,n=t,r=t);function i(l,u,c=0,h=l.length){if(c<h){if(e(u,u)!==0)return h;do{const f=c+h>>>1;n(l[f],u)<0?c=f+1:h=f}while(c<h)}return c}function a(l,u,c=0,h=l.length){if(c<h){if(e(u,u)!==0)return h;do{const f=c+h>>>1;n(l[f],u)<=0?c=f+1:h=f}while(c<h)}return c}function o(l,u,c=0,h=l.length){const f=i(l,u,c,h-1);return f>c&&r(l[f-1],u)>-r(l[f],u)?f-1:f}return{left:i,center:o,right:a}}function _o(){return 0}function zo(t){return t===null?NaN:+t}const Ao=lr(ft),Zo=Ao.right;lr(zo).center;const Io=Math.sqrt(50),No=Math.sqrt(10),Bo=Math.sqrt(2);function Yt(t,e,n){const r=(e-t)/Math.max(0,n),i=Math.floor(Math.log10(r)),a=r/Math.pow(10,i),o=a>=Io?10:a>=No?5:a>=Bo?2:1;let l,u,c;return i<0?(c=Math.pow(10,-i)/o,l=Math.round(t*c),u=Math.round(e*c),l/c<t&&++l,u/c>e&&--u,c=-c):(c=Math.pow(10,i)*o,l=Math.round(t/c),u=Math.round(e/c),l*c<t&&++l,u*c>e&&--u),u<l&&.5<=n&&n<2?Yt(t,e,n*2):[l,u,c]}function Uo(t,e,n){if(e=+e,t=+t,n=+n,!(n>0))return[];if(t===e)return[t];const r=e<t,[i,a,o]=r?Yt(e,t,n):Yt(t,e,n);if(!(a>=i))return[];const l=a-i+1,u=new Array(l);if(r)if(o<0)for(let c=0;c<l;++c)u[c]=(a-c)/-o;else for(let c=0;c<l;++c)u[c]=(a-c)*o;else if(o<0)for(let c=0;c<l;++c)u[c]=(i+c)/-o;else for(let c=0;c<l;++c)u[c]=(i+c)*o;return u}function Rn(t,e,n){return e=+e,t=+t,n=+n,Yt(t,e,n)[2]}function Mn(t,e,n){e=+e,t=+t,n=+n;const r=e<t,i=r?Rn(e,t,n):Rn(t,e,n);return(r?-1:1)*(i<0?1/-i:i)}function wi(t,e){switch(arguments.length){case 0:break;case 1:this.range(t);break;default:this.range(e).domain(t);break}return this}function cr(t,e,n){t.prototype=e.prototype=n,n.constructor=t}function Ti(t,e){var n=Object.create(t.prototype);for(var r in e)n[r]=e[r];return n}function st(){}var He=.7,$t=1/He,we="\\s*([+-]?\\d+)\\s*",Je="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*",J="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*",qo=/^#([0-9a-f]{3,8})$/,Fo=new RegExp(`^rgb\\(${we},${we},${we}\\)$`),Wo=new RegExp(`^rgb\\(${J},${J},${J}\\)$`),Ho=new RegExp(`^rgba\\(${we},${we},${we},${Je}\\)$`),Jo=new RegExp(`^rgba\\(${J},${J},${J},${Je}\\)$`),jo=new RegExp(`^hsl\\(${Je},${J},${J}\\)$`),Vo=new RegExp(`^hsla\\(${Je},${J},${J},${Je}\\)$`),Lr={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};cr(st,Ye,{copy(t){return Object.assign(new this.constructor,this,t)},displayable(){return this.rgb().displayable()},hex:Or,formatHex:Or,formatHex8:Go,formatHsl:Xo,formatRgb:Yr,toString:Yr});function Or(){return this.rgb().formatHex()}function Go(){return this.rgb().formatHex8()}function Xo(){return Ei(this).formatHsl()}function Yr(){return this.rgb().formatRgb()}function Ye(t){var e,n;return t=(t+"").trim().toLowerCase(),(e=qo.exec(t))?(n=e[1].length,e=parseInt(e[1],16),n===6?$r(e):n===3?new Z(e>>8&15|e>>4&240,e>>4&15|e&240,(e&15)<<4|e&15,1):n===8?ut(e>>24&255,e>>16&255,e>>8&255,(e&255)/255):n===4?ut(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(t))?new Z(e[1],e[2],e[3],1):(e=Wo.exec(t))?new Z(e[1]*255/100,e[2]*255/100,e[3]*255/100,1):(e=Ho.exec(t))?ut(e[1],e[2],e[3],e[4]):(e=Jo.exec(t))?ut(e[1]*255/100,e[2]*255/100,e[3]*255/100,e[4]):(e=jo.exec(t))?zr(e[1],e[2]/100,e[3]/100,1):(e=Vo.exec(t))?zr(e[1],e[2]/100,e[3]/100,e[4]):Lr.hasOwnProperty(t)?$r(Lr[t]):t==="transparent"?new Z(NaN,NaN,NaN,0):null}function $r(t){return new Z(t>>16&255,t>>8&255,t&255,1)}function ut(t,e,n,r){return r<=0&&(t=e=n=NaN),new Z(t,e,n,r)}function Ko(t){return t instanceof st||(t=Ye(t)),t?(t=t.rgb(),new Z(t.r,t.g,t.b,t.opacity)):new Z}function Ln(t,e,n,r){return arguments.length===1?Ko(t):new Z(t,e,n,r??1)}function Z(t,e,n,r){this.r=+t,this.g=+e,this.b=+n,this.opacity=+r}cr(Z,Ln,Ti(st,{brighter(t){return t=t==null?$t:Math.pow($t,t),new Z(this.r*t,this.g*t,this.b*t,this.opacity)},darker(t){return t=t==null?He:Math.pow(He,t),new Z(this.r*t,this.g*t,this.b*t,this.opacity)},rgb(){return this},clamp(){return new Z(oe(this.r),oe(this.g),oe(this.b),Dt(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:Dr,formatHex:Dr,formatHex8:Qo,formatRgb:_r,toString:_r}));function Dr(){return`#${ae(this.r)}${ae(this.g)}${ae(this.b)}`}function Qo(){return`#${ae(this.r)}${ae(this.g)}${ae(this.b)}${ae((isNaN(this.opacity)?1:this.opacity)*255)}`}function _r(){const t=Dt(this.opacity);return`${t===1?"rgb(":"rgba("}${oe(this.r)}, ${oe(this.g)}, ${oe(this.b)}${t===1?")":`, ${t})`}`}function Dt(t){return isNaN(t)?1:Math.max(0,Math.min(1,t))}function oe(t){return Math.max(0,Math.min(255,Math.round(t)||0))}function ae(t){return t=oe(t),(t<16?"0":"")+t.toString(16)}function zr(t,e,n,r){return r<=0?t=e=n=NaN:n<=0||n>=1?t=e=NaN:e<=0&&(t=NaN),new H(t,e,n,r)}function Ei(t){if(t instanceof H)return new H(t.h,t.s,t.l,t.opacity);if(t instanceof st||(t=Ye(t)),!t)return new H;if(t instanceof H)return t;t=t.rgb();var e=t.r/255,n=t.g/255,r=t.b/255,i=Math.min(e,n,r),a=Math.max(e,n,r),o=NaN,l=a-i,u=(a+i)/2;return l?(e===a?o=(n-r)/l+(n<r)*6:n===a?o=(r-e)/l+2:o=(e-n)/l+4,l/=u<.5?a+i:2-a-i,o*=60):l=u>0&&u<1?0:o,new H(o,l,u,t.opacity)}function el(t,e,n,r){return arguments.length===1?Ei(t):new H(t,e,n,r??1)}function H(t,e,n,r){this.h=+t,this.s=+e,this.l=+n,this.opacity=+r}cr(H,el,Ti(st,{brighter(t){return t=t==null?$t:Math.pow($t,t),new H(this.h,this.s,this.l*t,this.opacity)},darker(t){return t=t==null?He:Math.pow(He,t),new H(this.h,this.s,this.l*t,this.opacity)},rgb(){var t=this.h%360+(this.h<0)*360,e=isNaN(t)||isNaN(this.s)?0:this.s,n=this.l,r=n+(n<.5?n:1-n)*e,i=2*n-r;return new Z(rn(t>=240?t-240:t+120,i,r),rn(t,i,r),rn(t<120?t+240:t-120,i,r),this.opacity)},clamp(){return new H(Ar(this.h),ht(this.s),ht(this.l),Dt(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 t=Dt(this.opacity);return`${t===1?"hsl(":"hsla("}${Ar(this.h)}, ${ht(this.s)*100}%, ${ht(this.l)*100}%${t===1?")":`, ${t})`}`}}));function Ar(t){return t=(t||0)%360,t<0?t+360:t}function ht(t){return Math.max(0,Math.min(1,t||0))}function rn(t,e,n){return(t<60?e+(n-e)*t/60:t<180?n:t<240?e+(n-e)*(240-t)/60:e)*255}const ur=t=>()=>t;function tl(t,e){return function(n){return t+n*e}}function nl(t,e,n){return t=Math.pow(t,n),e=Math.pow(e,n)-t,n=1/n,function(r){return Math.pow(t+r*e,n)}}function rl(t){return(t=+t)==1?Ci:function(e,n){return n-e?nl(e,n,t):ur(isNaN(e)?n:e)}}function Ci(t,e){var n=e-t;return n?tl(t,n):ur(isNaN(t)?e:t)}const On=function t(e){var n=rl(e);function r(i,a){var o=n((i=Ln(i)).r,(a=Ln(a)).r),l=n(i.g,a.g),u=n(i.b,a.b),c=Ci(i.opacity,a.opacity);return function(h){return i.r=o(h),i.g=l(h),i.b=u(h),i.opacity=c(h),i+""}}return r.gamma=t,r}(1);function sl(t,e){e||(e=[]);var n=t?Math.min(e.length,t.length):0,r=e.slice(),i;return function(a){for(i=0;i<n;++i)r[i]=t[i]*(1-a)+e[i]*a;return r}}function il(t){return ArrayBuffer.isView(t)&&!(t instanceof DataView)}function al(t,e){var n=e?e.length:0,r=t?Math.min(n,t.length):0,i=new Array(r),a=new Array(n),o;for(o=0;o<r;++o)i[o]=en(t[o],e[o]);for(;o<n;++o)a[o]=e[o];return function(l){for(o=0;o<r;++o)a[o]=i[o](l);return a}}function ol(t,e){var n=new Date;return t=+t,e=+e,function(r){return n.setTime(t*(1-r)+e*r),n}}function je(t,e){return t=+t,e=+e,function(n){return t*(1-n)+e*n}}function ll(t,e){var n={},r={},i;(t===null||typeof t!="object")&&(t={}),(e===null||typeof e!="object")&&(e={});for(i in e)i in t?n[i]=en(t[i],e[i]):r[i]=e[i];return function(a){for(i in n)r[i]=n[i](a);return r}}var Yn=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,sn=new RegExp(Yn.source,"g");function cl(t){return function(){return t}}function ul(t){return function(e){return t(e)+""}}function Pi(t,e){var n=Yn.lastIndex=sn.lastIndex=0,r,i,a,o=-1,l=[],u=[];for(t=t+"",e=e+"";(r=Yn.exec(t))&&(i=sn.exec(e));)(a=i.index)>n&&(a=e.slice(n,a),l[o]?l[o]+=a:l[++o]=a),(r=r[0])===(i=i[0])?l[o]?l[o]+=i:l[++o]=i:(l[++o]=null,u.push({i:o,x:je(r,i)})),n=sn.lastIndex;return n<e.length&&(a=e.slice(n),l[o]?l[o]+=a:l[++o]=a),l.length<2?u[0]?ul(u[0].x):cl(e):(e=u.length,function(c){for(var h=0,f;h<e;++h)l[(f=u[h]).i]=f.x(c);return l.join("")})}function en(t,e){var n=typeof e,r;return e==null||n==="boolean"?ur(e):(n==="number"?je:n==="string"?(r=Ye(e))?(e=r,On):Pi:e instanceof Ye?On:e instanceof Date?ol:il(e)?sl:Array.isArray(e)?al:typeof e.valueOf!="function"&&typeof e.toString!="function"||isNaN(e)?ll:je)(t,e)}function hl(t,e){return t=+t,e=+e,function(n){return Math.round(t*(1-n)+e*n)}}function dl(t){return function(){return t}}function fl(t){return+t}var Zr=[0,1];function be(t){return t}function $n(t,e){return(e-=t=+t)?function(n){return(n-t)/e}:dl(isNaN(e)?NaN:.5)}function pl(t,e){var n;return t>e&&(n=t,t=e,e=n),function(r){return Math.max(t,Math.min(e,r))}}function gl(t,e,n){var r=t[0],i=t[1],a=e[0],o=e[1];return i<r?(r=$n(i,r),a=n(o,a)):(r=$n(r,i),a=n(a,o)),function(l){return a(r(l))}}function ml(t,e,n){var r=Math.min(t.length,e.length)-1,i=new Array(r),a=new Array(r),o=-1;for(t[r]<t[0]&&(t=t.slice().reverse(),e=e.slice().reverse());++o<r;)i[o]=$n(t[o],t[o+1]),a[o]=n(e[o],e[o+1]);return function(l){var u=Zo(t,l,1,r)-1;return a[u](i[u](l))}}function ki(t,e){return e.domain(t.domain()).range(t.range()).interpolate(t.interpolate()).clamp(t.clamp()).unknown(t.unknown())}function yl(){var t=Zr,e=Zr,n=en,r,i,a,o=be,l,u,c;function h(){var g=Math.min(t.length,e.length);return o!==be&&(o=pl(t[0],t[g-1])),l=g>2?ml:gl,u=c=null,f}function f(g){return g==null||isNaN(g=+g)?a:(u||(u=l(t.map(r),e,n)))(r(o(g)))}return f.invert=function(g){return o(i((c||(c=l(e,t.map(r),je)))(g)))},f.domain=function(g){return arguments.length?(t=Array.from(g,fl),h()):t.slice()},f.range=function(g){return arguments.length?(e=Array.from(g),h()):e.slice()},f.rangeRound=function(g){return e=Array.from(g),n=hl,h()},f.clamp=function(g){return arguments.length?(o=g?!0:be,h()):o!==be},f.interpolate=function(g){return arguments.length?(n=g,h()):n},f.unknown=function(g){return arguments.length?(a=g,f):a},function(g,v){return r=g,i=v,h()}}function Ri(){return yl()(be,be)}function vl(t){return Math.abs(t=Math.round(t))>=1e21?t.toLocaleString("en").replace(/,/g,""):t.toString(10)}function _t(t,e){if((n=(t=e?t.toExponential(e-1):t.toExponential()).indexOf("e"))<0)return null;var n,r=t.slice(0,n);return[r.length>1?r[0]+r.slice(2):r,+t.slice(n+1)]}function $e(t){return t=_t(Math.abs(t)),t?t[1]:NaN}function bl(t,e){return function(n,r){for(var i=n.length,a=[],o=0,l=t[0],u=0;i>0&&l>0&&(u+l+1>r&&(l=Math.max(1,r-u)),a.push(n.substring(i-=l,i+l)),!((u+=l+1)>r));)l=t[o=(o+1)%t.length];return a.reverse().join(e)}}function Sl(t){return function(e){return e.replace(/[0-9]/g,function(n){return t[+n]})}}var xl=/^(?:(.)?([<>=^]))?([+\-( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;function zt(t){if(!(e=xl.exec(t)))throw new Error("invalid format: "+t);var e;return new hr({fill:e[1],align:e[2],sign:e[3],symbol:e[4],zero:e[5],width:e[6],comma:e[7],precision:e[8]&&e[8].slice(1),trim:e[9],type:e[10]})}zt.prototype=hr.prototype;function hr(t){this.fill=t.fill===void 0?" ":t.fill+"",this.align=t.align===void 0?">":t.align+"",this.sign=t.sign===void 0?"-":t.sign+"",this.symbol=t.symbol===void 0?"":t.symbol+"",this.zero=!!t.zero,this.width=t.width===void 0?void 0:+t.width,this.comma=!!t.comma,this.precision=t.precision===void 0?void 0:+t.precision,this.trim=!!t.trim,this.type=t.type===void 0?"":t.type+""}hr.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 wl(t){e:for(var e=t.length,n=1,r=-1,i;n<e;++n)switch(t[n]){case".":r=i=n;break;case"0":r===0&&(r=n),i=n;break;default:if(!+t[n])break e;r>0&&(r=0);break}return r>0?t.slice(0,r)+t.slice(i+1):t}var Mi;function Tl(t,e){var n=_t(t,e);if(!n)return t+"";var r=n[0],i=n[1],a=i-(Mi=Math.max(-8,Math.min(8,Math.floor(i/3)))*3)+1,o=r.length;return a===o?r:a>o?r+new Array(a-o+1).join("0"):a>0?r.slice(0,a)+"."+r.slice(a):"0."+new Array(1-a).join("0")+_t(t,Math.max(0,e+a-1))[0]}function Ir(t,e){var n=_t(t,e);if(!n)return t+"";var r=n[0],i=n[1];return i<0?"0."+new Array(-i).join("0")+r:r.length>i+1?r.slice(0,i+1)+"."+r.slice(i+1):r+new Array(i-r.length+2).join("0")}const Nr={"%":(t,e)=>(t*100).toFixed(e),b:t=>Math.round(t).toString(2),c:t=>t+"",d:vl,e:(t,e)=>t.toExponential(e),f:(t,e)=>t.toFixed(e),g:(t,e)=>t.toPrecision(e),o:t=>Math.round(t).toString(8),p:(t,e)=>Ir(t*100,e),r:Ir,s:Tl,X:t=>Math.round(t).toString(16).toUpperCase(),x:t=>Math.round(t).toString(16)};function Br(t){return t}var Ur=Array.prototype.map,qr=["y","z","a","f","p","n","µ","m","","k","M","G","T","P","E","Z","Y"];function El(t){var e=t.grouping===void 0||t.thousands===void 0?Br:bl(Ur.call(t.grouping,Number),t.thousands+""),n=t.currency===void 0?"":t.currency[0]+"",r=t.currency===void 0?"":t.currency[1]+"",i=t.decimal===void 0?".":t.decimal+"",a=t.numerals===void 0?Br:Sl(Ur.call(t.numerals,String)),o=t.percent===void 0?"%":t.percent+"",l=t.minus===void 0?"−":t.minus+"",u=t.nan===void 0?"NaN":t.nan+"";function c(f){f=zt(f);var g=f.fill,v=f.align,w=f.sign,b=f.symbol,S=f.zero,R=f.width,L=f.comma,k=f.precision,O=f.trim,$=f.type;$==="n"?(L=!0,$="g"):Nr[$]||(k===void 0&&(k=12),O=!0,$="g"),(S||g==="0"&&v==="=")&&(S=!0,g="0",v="=");var x=b==="$"?n:b==="#"&&/[boxX]/.test($)?"0"+$.toLowerCase():"",Y=b==="$"?r:/[%p]/.test($)?o:"",ee=Nr[$],Ie=/[defgprs%]/.test($);k=k===void 0?6:/[gprs]/.test($)?Math.max(1,Math.min(21,k)):Math.max(0,Math.min(20,k));function pe(E){var j=x,z=Y,te,lt,ge;if($==="c")z=ee(E)+z,E="";else{E=+E;var me=E<0||1/E<0;if(E=isNaN(E)?u:ee(Math.abs(E),k),O&&(E=wl(E)),me&&+E==0&&w!=="+"&&(me=!1),j=(me?w==="("?w:l:w==="-"||w==="("?"":w)+j,z=($==="s"?qr[8+Mi/3]:"")+z+(me&&w==="("?")":""),Ie){for(te=-1,lt=E.length;++te<lt;)if(ge=E.charCodeAt(te),48>ge||ge>57){z=(ge===46?i+E.slice(te+1):E.slice(te))+z,E=E.slice(0,te);break}}}L&&!S&&(E=e(E,1/0));var ye=j.length+E.length+z.length,W=ye<R?new Array(R-ye+1).join(g):"";switch(L&&S&&(E=e(W+E,W.length?R-z.length:1/0),W=""),v){case"<":E=j+E+z+W;break;case"=":E=j+W+E+z;break;case"^":E=W.slice(0,ye=W.length>>1)+j+E+z+W.slice(ye);break;default:E=W+j+E+z;break}return a(E)}return pe.toString=function(){return f+""},pe}function h(f,g){var v=c((f=zt(f),f.type="f",f)),w=Math.max(-8,Math.min(8,Math.floor($e(g)/3)))*3,b=Math.pow(10,-w),S=qr[8+w/3];return function(R){return v(b*R)+S}}return{format:c,formatPrefix:h}}var dt,Li,Oi;Cl({thousands:",",grouping:[3],currency:["$",""]});function Cl(t){return dt=El(t),Li=dt.format,Oi=dt.formatPrefix,dt}function Pl(t){return Math.max(0,-$e(Math.abs(t)))}function kl(t,e){return Math.max(0,Math.max(-8,Math.min(8,Math.floor($e(e)/3)))*3-$e(Math.abs(t)))}function Rl(t,e){return t=Math.abs(t),e=Math.abs(e)-t,Math.max(0,$e(e)-$e(t))+1}function Ml(t,e,n,r){var i=Mn(t,e,n),a;switch(r=zt(r??",f"),r.type){case"s":{var o=Math.max(Math.abs(t),Math.abs(e));return r.precision==null&&!isNaN(a=kl(i,o))&&(r.precision=a),Oi(r,o)}case"":case"e":case"g":case"p":case"r":{r.precision==null&&!isNaN(a=Rl(i,Math.max(Math.abs(t),Math.abs(e))))&&(r.precision=a-(r.type==="e"));break}case"f":case"%":{r.precision==null&&!isNaN(a=Pl(i))&&(r.precision=a-(r.type==="%")*2);break}}return Li(r)}function Ll(t){var e=t.domain;return t.ticks=function(n){var r=e();return Uo(r[0],r[r.length-1],n??10)},t.tickFormat=function(n,r){var i=e();return Ml(i[0],i[i.length-1],n??10,r)},t.nice=function(n){n==null&&(n=10);var r=e(),i=0,a=r.length-1,o=r[i],l=r[a],u,c,h=10;for(l<o&&(c=o,o=l,l=c,c=i,i=a,a=c);h-- >0;){if(c=Rn(o,l,n),c===u)return r[i]=o,r[a]=l,e(r);if(c>0)o=Math.floor(o/c)*c,l=Math.ceil(l/c)*c;else if(c<0)o=Math.ceil(o*c)/c,l=Math.floor(l*c)/c;else break;u=c}return t},t}function Yi(){var t=Ri();return t.copy=function(){return ki(t,Yi())},wi.apply(t,arguments),Ll(t)}function Ol(t,e){t=t.slice();var n=0,r=t.length-1,i=t[n],a=t[r],o;return a<i&&(o=n,n=r,r=o,o=i,i=a,a=o),t[n]=e.floor(i),t[r]=e.ceil(a),t}const an=new Date,on=new Date;function D(t,e,n,r){function i(a){return t(a=arguments.length===0?new Date:new Date(+a)),a}return i.floor=a=>(t(a=new Date(+a)),a),i.ceil=a=>(t(a=new Date(a-1)),e(a,1),t(a),a),i.round=a=>{const o=i(a),l=i.ceil(a);return a-o<l-a?o:l},i.offset=(a,o)=>(e(a=new Date(+a),o==null?1:Math.floor(o)),a),i.range=(a,o,l)=>{const u=[];if(a=i.ceil(a),l=l==null?1:Math.floor(l),!(a<o)||!(l>0))return u;let c;do u.push(c=new Date(+a)),e(a,l),t(a);while(c<a&&a<o);return u},i.filter=a=>D(o=>{if(o>=o)for(;t(o),!a(o);)o.setTime(o-1)},(o,l)=>{if(o>=o)if(l<0)for(;++l<=0;)for(;e(o,-1),!a(o););else for(;--l>=0;)for(;e(o,1),!a(o););}),n&&(i.count=(a,o)=>(an.setTime(+a),on.setTime(+o),t(an),t(on),Math.floor(n(an,on))),i.every=a=>(a=Math.floor(a),!isFinite(a)||!(a>0)?null:a>1?i.filter(r?o=>r(o)%a===0:o=>i.count(0,o)%a===0):i)),i}const At=D(()=>{},(t,e)=>{t.setTime(+t+e)},(t,e)=>e-t);At.every=t=>(t=Math.floor(t),!isFinite(t)||!(t>0)?null:t>1?D(e=>{e.setTime(Math.floor(e/t)*t)},(e,n)=>{e.setTime(+e+n*t)},(e,n)=>(n-e)/t):At);At.range;const V=1e3,U=V*60,G=U*60,K=G*24,dr=K*7,Fr=K*30,ln=K*365,Se=D(t=>{t.setTime(t-t.getMilliseconds())},(t,e)=>{t.setTime(+t+e*V)},(t,e)=>(e-t)/V,t=>t.getUTCSeconds());Se.range;const fr=D(t=>{t.setTime(t-t.getMilliseconds()-t.getSeconds()*V)},(t,e)=>{t.setTime(+t+e*U)},(t,e)=>(e-t)/U,t=>t.getMinutes());fr.range;const Yl=D(t=>{t.setUTCSeconds(0,0)},(t,e)=>{t.setTime(+t+e*U)},(t,e)=>(e-t)/U,t=>t.getUTCMinutes());Yl.range;const pr=D(t=>{t.setTime(t-t.getMilliseconds()-t.getSeconds()*V-t.getMinutes()*U)},(t,e)=>{t.setTime(+t+e*G)},(t,e)=>(e-t)/G,t=>t.getHours());pr.range;const $l=D(t=>{t.setUTCMinutes(0,0,0)},(t,e)=>{t.setTime(+t+e*G)},(t,e)=>(e-t)/G,t=>t.getUTCHours());$l.range;const it=D(t=>t.setHours(0,0,0,0),(t,e)=>t.setDate(t.getDate()+e),(t,e)=>(e-t-(e.getTimezoneOffset()-t.getTimezoneOffset())*U)/K,t=>t.getDate()-1);it.range;const gr=D(t=>{t.setUTCHours(0,0,0,0)},(t,e)=>{t.setUTCDate(t.getUTCDate()+e)},(t,e)=>(e-t)/K,t=>t.getUTCDate()-1);gr.range;const Dl=D(t=>{t.setUTCHours(0,0,0,0)},(t,e)=>{t.setUTCDate(t.getUTCDate()+e)},(t,e)=>(e-t)/K,t=>Math.floor(t/K));Dl.range;function he(t){return D(e=>{e.setDate(e.getDate()-(e.getDay()+7-t)%7),e.setHours(0,0,0,0)},(e,n)=>{e.setDate(e.getDate()+n*7)},(e,n)=>(n-e-(n.getTimezoneOffset()-e.getTimezoneOffset())*U)/dr)}const tn=he(0),Zt=he(1),_l=he(2),zl=he(3),De=he(4),Al=he(5),Zl=he(6);tn.range;Zt.range;_l.range;zl.range;De.range;Al.range;Zl.range;function de(t){return D(e=>{e.setUTCDate(e.getUTCDate()-(e.getUTCDay()+7-t)%7),e.setUTCHours(0,0,0,0)},(e,n)=>{e.setUTCDate(e.getUTCDate()+n*7)},(e,n)=>(n-e)/dr)}const $i=de(0),It=de(1),Il=de(2),Nl=de(3),_e=de(4),Bl=de(5),Ul=de(6);$i.range;It.range;Il.range;Nl.range;_e.range;Bl.range;Ul.range;const mr=D(t=>{t.setDate(1),t.setHours(0,0,0,0)},(t,e)=>{t.setMonth(t.getMonth()+e)},(t,e)=>e.getMonth()-t.getMonth()+(e.getFullYear()-t.getFullYear())*12,t=>t.getMonth());mr.range;const ql=D(t=>{t.setUTCDate(1),t.setUTCHours(0,0,0,0)},(t,e)=>{t.setUTCMonth(t.getUTCMonth()+e)},(t,e)=>e.getUTCMonth()-t.getUTCMonth()+(e.getUTCFullYear()-t.getUTCFullYear())*12,t=>t.getUTCMonth());ql.range;const Q=D(t=>{t.setMonth(0,1),t.setHours(0,0,0,0)},(t,e)=>{t.setFullYear(t.getFullYear()+e)},(t,e)=>e.getFullYear()-t.getFullYear(),t=>t.getFullYear());Q.every=t=>!isFinite(t=Math.floor(t))||!(t>0)?null:D(e=>{e.setFullYear(Math.floor(e.getFullYear()/t)*t),e.setMonth(0,1),e.setHours(0,0,0,0)},(e,n)=>{e.setFullYear(e.getFullYear()+n*t)});Q.range;const ce=D(t=>{t.setUTCMonth(0,1),t.setUTCHours(0,0,0,0)},(t,e)=>{t.setUTCFullYear(t.getUTCFullYear()+e)},(t,e)=>e.getUTCFullYear()-t.getUTCFullYear(),t=>t.getUTCFullYear());ce.every=t=>!isFinite(t=Math.floor(t))||!(t>0)?null:D(e=>{e.setUTCFullYear(Math.floor(e.getUTCFullYear()/t)*t),e.setUTCMonth(0,1),e.setUTCHours(0,0,0,0)},(e,n)=>{e.setUTCFullYear(e.getUTCFullYear()+n*t)});ce.range;function Fl(t,e,n,r,i,a){const o=[[Se,1,V],[Se,5,5*V],[Se,15,15*V],[Se,30,30*V],[a,1,U],[a,5,5*U],[a,15,15*U],[a,30,30*U],[i,1,G],[i,3,3*G],[i,6,6*G],[i,12,12*G],[r,1,K],[r,2,2*K],[n,1,dr],[e,1,Fr],[e,3,3*Fr],[t,1,ln]];function l(c,h,f){const g=h<c;g&&([c,h]=[h,c]);const v=f&&typeof f.range=="function"?f:u(c,h,f),w=v?v.range(c,+h+1):[];return g?w.reverse():w}function u(c,h,f){const g=Math.abs(h-c)/f,v=lr(([,,S])=>S).right(o,g);if(v===o.length)return t.every(Mn(c/ln,h/ln,f));if(v===0)return At.every(Math.max(Mn(c,h,f),1));const[w,b]=o[g/o[v-1][2]<o[v][2]/g?v-1:v];return w.every(b)}return[l,u]}const[Wl,Hl]=Fl(Q,mr,tn,it,pr,fr);function cn(t){if(0<=t.y&&t.y<100){var e=new Date(-1,t.m,t.d,t.H,t.M,t.S,t.L);return e.setFullYear(t.y),e}return new Date(t.y,t.m,t.d,t.H,t.M,t.S,t.L)}function un(t){if(0<=t.y&&t.y<100){var e=new Date(Date.UTC(-1,t.m,t.d,t.H,t.M,t.S,t.L));return e.setUTCFullYear(t.y),e}return new Date(Date.UTC(t.y,t.m,t.d,t.H,t.M,t.S,t.L))}function Ne(t,e,n){return{y:t,m:e,d:n,H:0,M:0,S:0,L:0}}function Jl(t){var e=t.dateTime,n=t.date,r=t.time,i=t.periods,a=t.days,o=t.shortDays,l=t.months,u=t.shortMonths,c=Be(i),h=Ue(i),f=Be(a),g=Ue(a),v=Be(o),w=Ue(o),b=Be(l),S=Ue(l),R=Be(u),L=Ue(u),k={a:me,A:ye,b:W,B:oa,c:null,d:Gr,e:Gr,f:mc,g:Pc,G:Rc,H:fc,I:pc,j:gc,L:Di,m:yc,M:vc,p:la,q:ca,Q:Qr,s:es,S:bc,u:Sc,U:xc,V:wc,w:Tc,W:Ec,x:null,X:null,y:Cc,Y:kc,Z:Mc,"%":Kr},O={a:ua,A:ha,b:da,B:fa,c:null,d:Xr,e:Xr,f:$c,g:qc,G:Wc,H:Lc,I:Oc,j:Yc,L:zi,m:Dc,M:_c,p:pa,q:ga,Q:Qr,s:es,S:zc,u:Ac,U:Zc,V:Ic,w:Nc,W:Bc,x:null,X:null,y:Uc,Y:Fc,Z:Hc,"%":Kr},$={a:pe,A:E,b:j,B:z,c:te,d:jr,e:jr,f:cc,g:Jr,G:Hr,H:Vr,I:Vr,j:ic,L:lc,m:sc,M:ac,p:Ie,q:rc,Q:hc,s:dc,S:oc,u:Kl,U:Ql,V:ec,w:Xl,W:tc,x:lt,X:ge,y:Jr,Y:Hr,Z:nc,"%":uc};k.x=x(n,k),k.X=x(r,k),k.c=x(e,k),O.x=x(n,O),O.X=x(r,O),O.c=x(e,O);function x(y,T){return function(C){var m=[],A=-1,M=0,I=y.length,N,se,Tr;for(C instanceof Date||(C=new Date(+C));++A<I;)y.charCodeAt(A)===37&&(m.push(y.slice(M,A)),(se=Wr[N=y.charAt(++A)])!=null?N=y.charAt(++A):se=N==="e"?" ":"0",(Tr=T[N])&&(N=Tr(C,se)),m.push(N),M=A+1);return m.push(y.slice(M,A)),m.join("")}}function Y(y,T){return function(C){var m=Ne(1900,void 0,1),A=ee(m,y,C+="",0),M,I;if(A!=C.length)return null;if("Q"in m)return new Date(m.Q);if("s"in m)return new Date(m.s*1e3+("L"in m?m.L:0));if(T&&!("Z"in m)&&(m.Z=0),"p"in m&&(m.H=m.H%12+m.p*12),m.m===void 0&&(m.m="q"in m?m.q:0),"V"in m){if(m.V<1||m.V>53)return null;"w"in m||(m.w=1),"Z"in m?(M=un(Ne(m.y,0,1)),I=M.getUTCDay(),M=I>4||I===0?It.ceil(M):It(M),M=gr.offset(M,(m.V-1)*7),m.y=M.getUTCFullYear(),m.m=M.getUTCMonth(),m.d=M.getUTCDate()+(m.w+6)%7):(M=cn(Ne(m.y,0,1)),I=M.getDay(),M=I>4||I===0?Zt.ceil(M):Zt(M),M=it.offset(M,(m.V-1)*7),m.y=M.getFullYear(),m.m=M.getMonth(),m.d=M.getDate()+(m.w+6)%7)}else("W"in m||"U"in m)&&("w"in m||(m.w="u"in m?m.u%7:"W"in m?1:0),I="Z"in m?un(Ne(m.y,0,1)).getUTCDay():cn(Ne(m.y,0,1)).getDay(),m.m=0,m.d="W"in m?(m.w+6)%7+m.W*7-(I+5)%7:m.w+m.U*7-(I+6)%7);return"Z"in m?(m.H+=m.Z/100|0,m.M+=m.Z%100,un(m)):cn(m)}}function ee(y,T,C,m){for(var A=0,M=T.length,I=C.length,N,se;A<M;){if(m>=I)return-1;if(N=T.charCodeAt(A++),N===37){if(N=T.charAt(A++),se=$[N in Wr?T.charAt(A++):N],!se||(m=se(y,C,m))<0)return-1}else if(N!=C.charCodeAt(m++))return-1}return m}function Ie(y,T,C){var m=c.exec(T.slice(C));return m?(y.p=h.get(m[0].toLowerCase()),C+m[0].length):-1}function pe(y,T,C){var m=v.exec(T.slice(C));return m?(y.w=w.get(m[0].toLowerCase()),C+m[0].length):-1}function E(y,T,C){var m=f.exec(T.slice(C));return m?(y.w=g.get(m[0].toLowerCase()),C+m[0].length):-1}function j(y,T,C){var m=R.exec(T.slice(C));return m?(y.m=L.get(m[0].toLowerCase()),C+m[0].length):-1}function z(y,T,C){var m=b.exec(T.slice(C));return m?(y.m=S.get(m[0].toLowerCase()),C+m[0].length):-1}function te(y,T,C){return ee(y,e,T,C)}function lt(y,T,C){return ee(y,n,T,C)}function ge(y,T,C){return ee(y,r,T,C)}function me(y){return o[y.getDay()]}function ye(y){return a[y.getDay()]}function W(y){return u[y.getMonth()]}function oa(y){return l[y.getMonth()]}function la(y){return i[+(y.getHours()>=12)]}function ca(y){return 1+~~(y.getMonth()/3)}function ua(y){return o[y.getUTCDay()]}function ha(y){return a[y.getUTCDay()]}function da(y){return u[y.getUTCMonth()]}function fa(y){return l[y.getUTCMonth()]}function pa(y){return i[+(y.getUTCHours()>=12)]}function ga(y){return 1+~~(y.getUTCMonth()/3)}return{format:function(y){var T=x(y+="",k);return T.toString=function(){return y},T},parse:function(y){var T=Y(y+="",!1);return T.toString=function(){return y},T},utcFormat:function(y){var T=x(y+="",O);return T.toString=function(){return y},T},utcParse:function(y){var T=Y(y+="",!0);return T.toString=function(){return y},T}}}var Wr={"-":"",_:" ",0:"0"},_=/^\s*\d+/,jl=/^%/,Vl=/[\\^$*+?|[\]().{}]/g;function P(t,e,n){var r=t<0?"-":"",i=(r?-t:t)+"",a=i.length;return r+(a<n?new Array(n-a+1).join(e)+i:i)}function Gl(t){return t.replace(Vl,"\\$&")}function Be(t){return new RegExp("^(?:"+t.map(Gl).join("|")+")","i")}function Ue(t){return new Map(t.map((e,n)=>[e.toLowerCase(),n]))}function Xl(t,e,n){var r=_.exec(e.slice(n,n+1));return r?(t.w=+r[0],n+r[0].length):-1}function Kl(t,e,n){var r=_.exec(e.slice(n,n+1));return r?(t.u=+r[0],n+r[0].length):-1}function Ql(t,e,n){var r=_.exec(e.slice(n,n+2));return r?(t.U=+r[0],n+r[0].length):-1}function ec(t,e,n){var r=_.exec(e.slice(n,n+2));return r?(t.V=+r[0],n+r[0].length):-1}function tc(t,e,n){var r=_.exec(e.slice(n,n+2));return r?(t.W=+r[0],n+r[0].length):-1}function Hr(t,e,n){var r=_.exec(e.slice(n,n+4));return r?(t.y=+r[0],n+r[0].length):-1}function Jr(t,e,n){var r=_.exec(e.slice(n,n+2));return r?(t.y=+r[0]+(+r[0]>68?1900:2e3),n+r[0].length):-1}function nc(t,e,n){var r=/^(Z)|([+-]\d\d)(?::?(\d\d))?/.exec(e.slice(n,n+6));return r?(t.Z=r[1]?0:-(r[2]+(r[3]||"00")),n+r[0].length):-1}function rc(t,e,n){var r=_.exec(e.slice(n,n+1));return r?(t.q=r[0]*3-3,n+r[0].length):-1}function sc(t,e,n){var r=_.exec(e.slice(n,n+2));return r?(t.m=r[0]-1,n+r[0].length):-1}function jr(t,e,n){var r=_.exec(e.slice(n,n+2));return r?(t.d=+r[0],n+r[0].length):-1}function ic(t,e,n){var r=_.exec(e.slice(n,n+3));return r?(t.m=0,t.d=+r[0],n+r[0].length):-1}function Vr(t,e,n){var r=_.exec(e.slice(n,n+2));return r?(t.H=+r[0],n+r[0].length):-1}function ac(t,e,n){var r=_.exec(e.slice(n,n+2));return r?(t.M=+r[0],n+r[0].length):-1}function oc(t,e,n){var r=_.exec(e.slice(n,n+2));return r?(t.S=+r[0],n+r[0].length):-1}function lc(t,e,n){var r=_.exec(e.slice(n,n+3));return r?(t.L=+r[0],n+r[0].length):-1}function cc(t,e,n){var r=_.exec(e.slice(n,n+6));return r?(t.L=Math.floor(r[0]/1e3),n+r[0].length):-1}function uc(t,e,n){var r=jl.exec(e.slice(n,n+1));return r?n+r[0].length:-1}function hc(t,e,n){var r=_.exec(e.slice(n));return r?(t.Q=+r[0],n+r[0].length):-1}function dc(t,e,n){var r=_.exec(e.slice(n));return r?(t.s=+r[0],n+r[0].length):-1}function Gr(t,e){return P(t.getDate(),e,2)}function fc(t,e){return P(t.getHours(),e,2)}function pc(t,e){return P(t.getHours()%12||12,e,2)}function gc(t,e){return P(1+it.count(Q(t),t),e,3)}function Di(t,e){return P(t.getMilliseconds(),e,3)}function mc(t,e){return Di(t,e)+"000"}function yc(t,e){return P(t.getMonth()+1,e,2)}function vc(t,e){return P(t.getMinutes(),e,2)}function bc(t,e){return P(t.getSeconds(),e,2)}function Sc(t){var e=t.getDay();return e===0?7:e}function xc(t,e){return P(tn.count(Q(t)-1,t),e,2)}function _i(t){var e=t.getDay();return e>=4||e===0?De(t):De.ceil(t)}function wc(t,e){return t=_i(t),P(De.count(Q(t),t)+(Q(t).getDay()===4),e,2)}function Tc(t){return t.getDay()}function Ec(t,e){return P(Zt.count(Q(t)-1,t),e,2)}function Cc(t,e){return P(t.getFullYear()%100,e,2)}function Pc(t,e){return t=_i(t),P(t.getFullYear()%100,e,2)}function kc(t,e){return P(t.getFullYear()%1e4,e,4)}function Rc(t,e){var n=t.getDay();return t=n>=4||n===0?De(t):De.ceil(t),P(t.getFullYear()%1e4,e,4)}function Mc(t){var e=t.getTimezoneOffset();return(e>0?"-":(e*=-1,"+"))+P(e/60|0,"0",2)+P(e%60,"0",2)}function Xr(t,e){return P(t.getUTCDate(),e,2)}function Lc(t,e){return P(t.getUTCHours(),e,2)}function Oc(t,e){return P(t.getUTCHours()%12||12,e,2)}function Yc(t,e){return P(1+gr.count(ce(t),t),e,3)}function zi(t,e){return P(t.getUTCMilliseconds(),e,3)}function $c(t,e){return zi(t,e)+"000"}function Dc(t,e){return P(t.getUTCMonth()+1,e,2)}function _c(t,e){return P(t.getUTCMinutes(),e,2)}function zc(t,e){return P(t.getUTCSeconds(),e,2)}function Ac(t){var e=t.getUTCDay();return e===0?7:e}function Zc(t,e){return P($i.count(ce(t)-1,t),e,2)}function Ai(t){var e=t.getUTCDay();return e>=4||e===0?_e(t):_e.ceil(t)}function Ic(t,e){return t=Ai(t),P(_e.count(ce(t),t)+(ce(t).getUTCDay()===4),e,2)}function Nc(t){return t.getUTCDay()}function Bc(t,e){return P(It.count(ce(t)-1,t),e,2)}function Uc(t,e){return P(t.getUTCFullYear()%100,e,2)}function qc(t,e){return t=Ai(t),P(t.getUTCFullYear()%100,e,2)}function Fc(t,e){return P(t.getUTCFullYear()%1e4,e,4)}function Wc(t,e){var n=t.getUTCDay();return t=n>=4||n===0?_e(t):_e.ceil(t),P(t.getUTCFullYear()%1e4,e,4)}function Hc(){return"+0000"}function Kr(){return"%"}function Qr(t){return+t}function es(t){return Math.floor(+t/1e3)}var ve,Zi;Jc({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 Jc(t){return ve=Jl(t),Zi=ve.format,ve.parse,ve.utcFormat,ve.utcParse,ve}function jc(t){return new Date(t)}function Vc(t){return t instanceof Date?+t:+new Date(+t)}function Ii(t,e,n,r,i,a,o,l,u,c){var h=Ri(),f=h.invert,g=h.domain,v=c(".%L"),w=c(":%S"),b=c("%I:%M"),S=c("%I %p"),R=c("%a %d"),L=c("%b %d"),k=c("%B"),O=c("%Y");function $(x){return(u(x)<x?v:l(x)<x?w:o(x)<x?b:a(x)<x?S:r(x)<x?i(x)<x?R:L:n(x)<x?k:O)(x)}return h.invert=function(x){return new Date(f(x))},h.domain=function(x){return arguments.length?g(Array.from(x,Vc)):g().map(jc)},h.ticks=function(x){var Y=g();return t(Y[0],Y[Y.length-1],x??10)},h.tickFormat=function(x,Y){return Y==null?$:c(Y)},h.nice=function(x){var Y=g();return(!x||typeof x.range!="function")&&(x=e(Y[0],Y[Y.length-1],x??10)),x?g(Ol(Y,x)):h},h.copy=function(){return ki(h,Ii(t,e,n,r,i,a,o,l,u,c))},h}function Gc(){return wi.apply(Ii(Wl,Hl,Q,mr,tn,it,pr,fr,Se,Zi).domain([new Date(2e3,0,1),new Date(2e3,0,2)]),arguments)}const ts=[s.a.NANOSECOND,s.a.nanoseconds(2),s.a.nanoseconds(5),s.a.nanoseconds(10),s.a.nanoseconds(20),s.a.nanoseconds(50),s.a.nanoseconds(100),s.a.nanoseconds(200),s.a.nanoseconds(500),s.a.MICROSECOND,s.a.microseconds(2),s.a.microseconds(5),s.a.microseconds(10),s.a.microseconds(20),s.a.microseconds(50),s.a.microseconds(100),s.a.microseconds(200),s.a.microseconds(500),s.a.MILLISECOND,s.a.milliseconds(2),s.a.milliseconds(5),s.a.milliseconds(10),s.a.milliseconds(20),s.a.milliseconds(50),s.a.milliseconds(100),s.a.milliseconds(200),s.a.milliseconds(500),s.a.SECOND];class Xc{_domain;_range;_span;constructor(){this._domain=[new s.n(0n),new s.n(1n)],this._range=[0,1],this._span=this._domain[1].span(this._domain[0])}domain(e){return e===void 0?this._domain:(this._domain=[new s.n(e[0]),new s.n(e[1])],this._span=this._domain[1].span(this._domain[0]),this)}range(e){return e===void 0?this._range:(this._range=e,this)}scale(e){const r=new s.n(e).valueOf(),i=this._domain[0].valueOf(),a=this._domain[1].valueOf()-i,o=this._range[1]-this._range[0];return Number(r-i)/Number(a)*o+this._range[0]}ticks(e){const n=this.calculateOptimalStep(e).valueOf(),r=this._domain[0].valueOf(),i=this._domain[1].valueOf(),a=(r+n-1n)/n*n,o=Number((i-a)/n);return Array.from({length:o+1},(l,u)=>{const c=a+BigInt(u)*n;return new s.n(c)}).filter(l=>l.afterEq(this._domain[0])&&l.beforeEq(this._domain[1]))}calculateOptimalStep(e){const n=this._span.valueOf()/BigInt(Math.ceil(e));let r=ts[0];for(const i of ts){if(i.valueOf()>n)break;r=i}return r}formatTick(e){return this._span.lessThan(s.a.microseconds(50))?`${e.remainder(s.a.MILLISECOND).microseconds.toString()}µs`:`${e.remainder(s.a.SECOND).milliseconds.toString()}ms`}}const Kc=()=>new Xc,yr=d.z.enum(["linear","time"]),vr=d.z.object({tickSpacing:d.z.number().default(75),type:yr.optional().default("linear")}),Dn=t=>{const e=vr.parse(t);return tu[e.type](e)};class Qc{props;prevScaleSize;prevDomain;currTicks;normalScale;preciseScale;constructor(e){this.props=e,this.normalScale=Gc(),this.preciseScale=Kc(),this.prevScaleSize=0,this.prevDomain=new s.w(new s.n(0),new s.n(0)),this.currTicks=[]}create({decimalToDataScale:e,size:n}){const r=new s.w(new s.n(e.pos(0)),new s.n(e.pos(1)));if(this.prevDomain.equals(r)&&this.prevScaleSize===n)return this.currTicks;if(this.prevDomain=r,this.prevScaleSize!==n){const i=[0,n];this.preciseScale.range(i),this.normalScale.range(i),this.prevScaleSize=n}if(r.span.milliseconds<5){this.preciseScale.domain([r.start,r.end]);const i=_n(n,this.props.tickSpacing)/2,a=this.preciseScale.ticks(i);this.currTicks=a.map(o=>({label:this.preciseScale.formatTick(o),position:this.preciseScale.scale(o)}))}else{this.normalScale.domain([r.start.date(),r.end.date()]);const i=this.normalScale.ticks(_n(n,this.props.tickSpacing));this.currTicks=i.map(a=>({label:this.normalTickLabel(a),position:this.normalScale(a)}))}return this.currTicks}normalTickLabel(e){let n=`:${e.getSeconds()}`;const r=e.getMilliseconds();if(r!==0){const i=Math.round(e.getMilliseconds()).toString().padStart(3,"0").replace(/0+$/,"");n+=`.${i}`}return e.getSeconds()===0&&r===0&&(n=`${e.getHours()}:${e.getMinutes().toString().padStart(2,"0")}`),n}}class eu{props;prevDomain;prevScaleSize;currTicks;d3Scale;constructor(e){this.props=e,this.prevDomain=s.W.construct(0,0),this.prevScaleSize=0,this.currTicks=[],this.d3Scale=Yi()}create({decimalToDataScale:e,size:n}){const r={lower:e.pos(0),upper:e.pos(1)};if(s.W.equals(this.prevDomain,r)&&this.prevScaleSize===n)return this.currTicks;s.W.equals(this.prevDomain,r)||(this.d3Scale=this.d3Scale.domain([r.lower,r.upper])),this.prevScaleSize!==n&&(this.d3Scale=this.d3Scale.range([0,n])),this.prevDomain=r,this.prevScaleSize=n;const i=_n(n,this.props.tickSpacing),a=this.d3Scale.ticks(i);return this.currTicks=a.map(o=>({label:this.tickLabel(o),position:this.d3Scale(o)})),this.currTicks}tickLabel(e){return e.toString()}}const _n=(t,e)=>{const n=Math.floor(t/e);return n>0?n:1},tu={linear:t=>new eu(t),time:t=>new Qc(t)},br=vr.extend({color:s.ir.colorZ,type:yr.optional().default("linear"),font:d.z.string(),showGrid:d.z.boolean().optional().default(!0),location:s.K.outer,gridColor:s.ir.colorZ}),q=5,Ve=6,at={useAtlas:!0},nu={bottom:(t,e)=>new Bi(t,e),top:(t,e)=>new Ui(t,e),left:(t,e)=>new ru(t,e),right:(t,e)=>new qi(t,e)},Ni=(t,e,n)=>nu[t](e,n);class fe{renderCtx;state;tickFactory;constructor(e,n){this.renderCtx=e,this.state=n,this.tickFactory=Dn(this.state)}setState(e){this.state=p.prettyParse(br,e),this.tickFactory=Dn(e)}drawLine(e,n){const{lower2d:r}=this.renderCtx;r.moveTo(...s.J.couple(e)),r.lineTo(...s.J.couple(n))}drawTicks(e,n){let r=s._.ZERO;return e.forEach(i=>{const a=this.renderCtx.lower2d.textDimensions(i.label,at);r=s._.max([r,a]),n(a,i)}),r}static START_BOUND=s.W.construct(-1,1);maybeDrawGrid(e,n,r){const{showGrid:i,gridColor:a}=this.state;if(i){const o=fe.START_BOUND,l=s.W.construct(e-1,e+1),{lower2d:u}=this.renderCtx;u.beginPath(),u.strokeStyle=s.ir.hex(a),n.forEach(c=>{s.W.contains(o,c.position)||s.W.contains(l,c.position)||this.drawLine(...r(c))}),u.stroke()}}setColor(e){const n=s.ir.hex(e);this.renderCtx.lower2d.strokeStyle=n,this.renderCtx.lower2d.fillStyle=n,this.renderCtx.lower2d.font=this.state.font}}class Bi extends fe{render(e){const{lower2d:n}=this.renderCtx,{plot:r,position:i}=e,{width:a,height:o}=s.$t.dims(r),l=this.tickFactory.create({...e,size:a});n.beginPath(),this.setColor(this.state.color),this.drawLine(i,s.J.translate(i,"x",a));const u=this.drawTicks(l,(c,h)=>{this.drawLine(s.J.translateX(i,h.position),s.J.translate(i,{x:h.position,y:q})),n.fillText(h.label,i.x+h.position-c.width/2,i.y+q+c.height+Ve,void 0,at)});return n.stroke(),this.maybeDrawGrid(a,l,c=>[s.J.translate(i,"x",c.position),s.J.translate(i,{x:c.position,y:-o})]),{size:u.height+q+Ve}}}class Ui extends fe{render(e){const{lower2d:n}=this.renderCtx,{plot:r}=e,{width:i,height:a}=s.$t.dims(r),o=s.J.translate(e.position,"y",e.size),l=this.tickFactory.create({...e,size:i});n.beginPath(),this.setColor(this.state.color),this.drawLine(o,s.J.translate(o,"x",i));const u=this.drawTicks(l,(c,h)=>{this.drawLine(s.J.translateX(o,h.position),s.J.translate(o,{x:h.position,y:-q})),n.fillText(h.label,o.x+h.position-c.width/2,o.y-q-c.height-Ve,void 0,at)});return n.stroke(),this.maybeDrawGrid(i,l,c=>[s.J.translate(o,"x",c.position),s.J.translate(o,{x:c.position,y:a})]),{size:u.height+q}}}class ru extends fe{render(e){const{lower2d:n}=this.renderCtx,{plot:r,position:i}=e,{height:a,width:o}=s.$t.dims(r),l=s.J.translate(i,"x",e.size),u=this.tickFactory.create({...e,size:a});n.beginPath(),this.setColor(this.state.color),this.drawLine(l,s.J.translate(l,"y",a));const c=this.drawTicks(u,(h,f)=>{this.drawLine(s.J.translateY(l,f.position),s.J.translate(l,{x:-q,y:f.position})),n.fillText(f.label,l.x-h.width-q*2,l.y+f.position+h.height/2,void 0,at)});return n.stroke(),this.maybeDrawGrid(a,u,h=>[s.J.translate(l,"y",h.position),s.J.translate(l,{x:o,y:h.position})]),{size:c.width+q*2}}}class qi extends fe{render(e){const{lower2d:n}=this.renderCtx,{plot:r,position:i}=e,{height:a,width:o}=s.$t.dims(r),l=this.tickFactory.create({...e,size:a});n.beginPath(),this.setColor(this.state.color),this.drawLine(i,s.J.translateY(i,a));const u=this.drawTicks(l,(c,h)=>{this.drawLine(s.J.translateY(i,h.position),s.J.translate(i,{x:q,y:h.position})),n.fillText(h.label,i.x+q+Ve,i.y+h.position+c.height/2,void 0,at)});return n.stroke(),this.maybeDrawGrid(a,l,c=>[s.J.translateY(i,c.position),s.J.translate(i,{x:-o,y:c.position})]),{size:u.width+q+Ve}}}const ot=br.extend({axisKey:d.z.string().optional(),bounds:s.W.bounds.optional(),autoBounds:d.z.object({lower:d.z.boolean().optional().default(!0),upper:d.z.boolean().optional().default(!0)}).or(d.z.boolean().optional().default(!0)),autoBoundPadding:d.z.number().optional(),autoBoundUpdateInterval:s.a.z.optional().default(s.a.seconds(10)),size:d.z.number().optional().default(0),label:d.z.string().optional().default(""),labelSize:d.z.number().optional().default(0)}).partial({color:!0,font:!0,gridColor:!0}),su=2,iu=7,Fi=(t,e)=>s.W.contains({lower:t-iu,upper:t+su},e),au=s.W.DECIMAL,ns=s.n.now(),ou={lower:Number(ns.valueOf()),upper:Number(ns.add(s.a.HOUR).valueOf())},Wi=t=>t==="linear"?au:ou,lu=(t,e=.1,n)=>{const r=s.W.max(t.filter(s.W.isFinite));if(!s.W.isFinite(r))return Wi(n);const{lower:i,upper:a}=r;if(a===i)return{lower:i-1,upper:a+1};const o=(a-i)*e;return{lower:i-o,upper:a+o}},cu=.01,uu=.1;class Hi extends p.Composite{afterUpdate(e){const{internal:n}=this,{location:r,autoBoundUpdateInterval:i}=this.state;n.render=p.Context.use(e);const a=p.use(e),o=s.g.construct(r);this.state.autoBoundPadding??=o==="x"?uu:cu,n.core=Ni(r,n.render,{color:a.colors.gray.l10,font:Fe.fontString(a,{level:"small",code:!0}),gridColor:a.colors.gray.l1,...this.state}),X(e,"layout"),n.updateBounds??=p.r(l=>this.setState(u=>({...u,bounds:l})),i.milliseconds)}afterDelete(e){X(e,"layout")}renderAxis(e,n){if(!e.canvases.includes("lower2d"))return;const{core:r}=this.internal,{grid:i,container:a}=e,o=Yo(`${this.type}-${this.key}`,i,a),l={...e,position:o,decimalToDataScale:n,size:this.state.size+this.state.labelSize},{size:u}=r.render(l);Fi(this.state.size,u)||this.setState(c=>({...c,size:u}))}iBounds(e,n){if(e&&this.internal.boundSnapshot!=null)return[this.internal.boundSnapshot,null];const{lower:r,upper:i}=Ji(this.state.autoBounds);if(!r&&!i&&this.state.bounds!=null)return this.internal.boundSnapshot=this.state.bounds,[this.state.bounds,null];const a=c=>({upper:i||this.state.bounds==null?c.upper:this.state.bounds.upper,lower:r||this.state.bounds==null?c.lower:this.state.bounds.lower});let o,l=null;try{const c=n();o=lu(c,this.state.autoBoundPadding,this.state.type)}catch(c){o=Wi(this.state.type),l=c}const u=a(o);return this.internal.boundSnapshot=u,(this.state.bounds==null||r&&this.state.bounds.lower!==u.lower||i&&this.state.bounds.upper!==u.upper)&&this.internal.updateBounds?.(u),[u,l]}dataToDecimalScale(e,n,r){const[i,a]=this.iBounds(e,n),o=s.g.swap(s.g.construct(this.state.location));return[s.C.Scale.scale(i).scale(1).translate(-s.$t.root(r)[o]).magnify(1/s.$t.dim(r,o)),a]}}const Ji=t=>typeof t=="boolean"?{lower:t,upper:t}:{lower:t?.lower??!0,upper:t?.upper??!0};class Ze{canvas;theme;constructor(e,n){this.canvas=e,this.theme=n}rule({direction:e,region:n,position:r,...i}){return e==="x"?this.line({start:s.J.construct(s.$t.left(n),r),end:s.J.construct(s.$t.right(n),r),...i}):this.line({start:s.J.construct(r,s.$t.top(n)),end:s.J.construct(r,s.$t.bottom(n)),...i})}line({stroke:e,lineWidth:n,lineDash:r,start:i,end:a}){const o=this.canvas;o.strokeStyle=s.ir.hex(e),o.lineWidth=n,o.setLineDash([r]),o.beginPath(),o.moveTo(...s.J.couple(i)),o.lineTo(...s.J.couple(a)),o.stroke()}circle({fill:e,radius:n,position:r}){const i=this.canvas;i.fillStyle=s.ir.hex(e),i.beginPath(),i.arc(...s.J.couple(r),n,0,2*Math.PI),i.fill()}resolveColor(e,n){return e==null?n==null?this.theme.colors.text:this.resolveColor(n):typeof e=="function"?e(this.theme):s.ir.construct(e)}border({region:e,color:n,width:r,radius:i,location:a}){const o=this.canvas;o.strokeStyle=s.ir.hex(this.resolveColor(n,this.theme.colors.border)),o.lineWidth=r??this.theme.sizes.border.width,i??=this.theme.sizes.border.radius,a==null||a===!0?i>0?(o.roundRect(...s.J.couple(s.$t.topLeft(e)),...s.J.couple(s.$t.dims(e)),i),o.stroke()):(o.rect(...s.J.couple(s.$t.topLeft(e)),...s.J.couple(s.$t.dims(e))),o.stroke()):p.t.toArray(a).forEach(l=>{const[u,c]=s.$t.edgePoints(e,l);o.beginPath(),o.moveTo(...s.J.couple(u)),o.lineTo(...s.J.couple(c)),o.stroke()})}container({region:e,bordered:n=!0,rounded:r=!0,borderColor:i,borderRadius:a,borderWidth:o,backgroundColor:l}){a??=this.theme.sizes.border.radius,o??=1;const u=this.canvas;u.fillStyle=s.ir.hex(this.resolveColor(l,this.theme.colors.gray.l1)),u.strokeStyle=s.ir.hex(this.resolveColor(i,this.theme.colors.border)),u.setLineDash([]),u.lineWidth=1,u.beginPath(),r?u.roundRect(...s.J.couple(s.$t.topLeft(e)),...s.J.couple(s.$t.dims(e)),a):u.rect(...s.J.couple(s.$t.topLeft(e)),...s.J.couple(s.$t.dims(e))),u.fill(),n&&this.border({region:e,color:i,radius:a,width:o,location:n})}textContainer(e){const[n,r]=this.spacedTextDrawF(e);n.width+=12,n.height+=12;const{root:i=s.K.TOP_LEFT,offset:a=s.J.ZERO}=e,o={...e.position};i.x==="right"?o.x-=n.width+a.x:o.x+=a.x,i.y==="bottom"?o.y-=n.height+a.y:o.y+=a.y,this.container({region:s.$t.construct(o,n.width,n.height),...e}),this.canvas.filter="none",r(s.J.translate(o,[6,6]))}spacedTextDrawF({text:e,direction:n,spacing:r=1,level:i="p"}){const a=Fe.fontString(this.theme,{level:i}),o=e.map(c=>p.dimensions(c,a,this.canvas)),l=this.theme.sizes.base*r,u=Math.max(...o.map(c=>c[s.g.dimension(n)]))+l;return[{[s.g.dimension(s.g.swap(n))]:Math.max(...o.map(c=>c[s.g.dimension(s.g.swap(n))])),[s.g.dimension(n)]:u*e.length-l},c=>{const h=Fe.fontString(this.theme,{level:i});this.canvas.font=h,this.canvas.fillStyle=s.ir.hex(this.theme.colors.text),this.canvas.textBaseline="top",e.forEach((f,g)=>{this.canvas.fillText(f,c.x,c.y+u*g)})}]}list({length:e,itemHeight:n,width:r,spacing:i=0,position:a,draw:o,root:l=s.K.TOP_LEFT,offset:u=s.J.ZERO,padding:c=s.J.ZERO}){const h=e*n+c.y*2+i*(e-1),f=r+c.x*2,g={...a};l.x==="right"?g.x-=r+u.x*2:g.x+=u.x,l.y==="top"?g.y-=h+u.y*2:g.y+=u.y,this.container({region:s.$t.construct(g,{width:f,height:h}),backgroundColor:v=>v.colors.gray.l1});for(let v=0;v<e;v++){const w=s.$t.construct(s.J.construct(g.x+c.x,g.y+v*n+c.y+i*v),r,n);o(v,w)}}drawTextInCenter({box:e,text:n,level:r}){const i=p.dimensions(n,this.canvas.font,this.canvas),a=s.$t.positionInCenter(s.$t.construct(s.J.ZERO,i),e);return this.text({text:n,position:s.$t.topLeft(a),level:r})}text({text:e,position:n,level:r="p",weight:i,shade:a,maxWidth:o,code:l,justify:u="left",align:c="top",color:h}){this.canvas.font=Fe.fontString(this.theme,{level:r,weight:i,code:l}),h!=null?this.canvas.fillStyle=s.ir.hex(this.resolveColor(h)):a==null?this.canvas.fillStyle=s.ir.hex(this.theme.colors.text):this.canvas.fillStyle=s.ir.hex(this.theme.colors.gray[`l${a}`]),this.canvas.textAlign=u,this.canvas.textBaseline=c;let f;o!=null&&(f=this.canvas.scissor(s.$t.construct(n,o,1e3))),this.canvas.fillText(e,n.x,n.y),f?.()}}const Sr=d.z.object({position:d.z.number().optional(),pixelPosition:d.z.number().optional(),dragging:d.z.boolean(),lineWidth:d.z.number().optional().default(1),lineDash:d.z.number().optional().default(20),color:s.ir.colorZ}),hu=3;class Ge extends p.Leaf{static TYPE="Rule";schema=Sr;lastUpdateRef=null;afterUpdate(e){this.internal.renderCtx=p.Context.use(e);const n=p.use(e);this.internal.draw=new Ze(this.internal.renderCtx.upper2d,n),X(e,"tool")}afterDelete(e){X(e,"tool")}updatePositions({decimalToDataScale:e,plot:n}){const r=this.state.dragging,i=this.prevState.dragging&&!r;if((r||i)&&this.state.pixelPosition!=null){if(this.lastUpdateRef??=this.state.pixelPosition,Math.abs(this.state.pixelPosition-this.lastUpdateRef)<hu&&!i)return this.state.pixelPosition;this.lastUpdateRef=this.state.pixelPosition;const l=e.pos(this.state.pixelPosition/s.$t.height(n));return this.setState(u=>({...u,position:l})),this.state.pixelPosition}if(this.state.position==null){const o=e.pos(.5);this.setState(l=>({...l,position:o}))}const a=e.reverse().pos(this.state.position)*s.$t.height(n);if(!isNaN(a)){if(this.state.pixelPosition!=null&&Math.abs(a-this.state.pixelPosition)<1)return this.state.pixelPosition;this.setState(o=>({...o,pixelPosition:a}))}return a}render(e){if(this.deleted)return;const{renderCtx:n}=this.internal,{location:r,plot:i}=e,a=s.K.direction(r),{upper2d:o}=n,l=this.internal.draw,u=this.updatePositions(e)+s.$t.top(e.plot);l.rule({stroke:this.state.color,lineWidth:this.state.lineWidth,lineDash:this.state.lineDash,direction:a,region:i,position:u}),o.fillStyle=s.ir.hex(this.state.color),o.lineJoin="round",o.lineWidth=3.5,o.lineCap="round",o.beginPath();const c=4;if(r==="left"){const h=s.$t.left(i)-1;o.moveTo(h,u),o.lineTo(h-c,u-c),o.lineTo(h-c,u+c)}else r==="right"&&(o.moveTo(s.$t.right(i),u),o.lineTo(s.$t.right(i)+c,u-c),o.lineTo(s.$t.right(i)+c,u+c));o.closePath(),o.stroke()}}const ji={[Ge.TYPE]:Ge},du=Object.freeze(Object.defineProperty({__proto__:null,REGISTRY:ji,Rule:Ge,ruleStateZ:Sr},Symbol.toStringTag,{value:"Module"})),fu=ot.extend({location:s.K.x.optional().default("left")}),rs=2,pu=t=>s.$t.signedWidth(t)<rs||s.$t.signedHeight(t)<rs;class Nt extends Hi{static TYPE="YAxis";schema=ot;xBounds(){return s.W.max(this.lines.map(e=>e.xBounds()).filter(e=>s.W.isFinite(e)))}bounds(e){const[n,r]=this.iBounds(e,this.dataBounds.bind(this));if(r!=null)throw r;return n}render(e){if(this.deleted)return;const[n,r]=this.dataToDecimalScale(e.hold,this.dataBounds.bind(this),e.viewport),i=n.invert().reverse();if(this.renderAxis(e,i),this.renderLines(e,n),this.renderRules(e,i),r!=null)throw r}renderLines({xDataToDecimalScale:e,plot:n,canvases:r,exposure:i},a){if(!r.includes("gl")||pu(n))return;const o={region:n,dataToDecimalScale:new s.C.XY(e,a),exposure:i};this.lines.forEach(l=>l.render(o))}renderRules({container:e,plot:n,canvases:r},i){if(!r.includes("upper2d"))return;const{location:a}=this.state,{render:o}=this.internal,l=s.$t.construct(s.$t.left(e),s.$t.top(n),s.$t.width(e),s.$t.height(n)),u=o.scissor(l,s.J.ZERO,["upper2d"]),c={container:e,plot:n,decimalToDataScale:i,location:a};this.rules.map(h=>h.render(c)),u()}findByXValue({xDataToDecimalScale:e,plot:n,viewport:r,hold:i,exposure:a},o){const[l,u]=this.dataToDecimalScale(i,this.dataBounds.bind(this),r);if(u!=null)throw u;const c=new s.C.XY(e,l),h={region:n,dataToDecimalScale:c,exposure:a};return this.lines.map(f=>({...f.findByXValue(h,o),units:this.state.label}))}dataBounds(){return this.lines.map(e=>e.yBounds())}get lines(){return this.childrenOfType(Mt.TYPE)}get rules(){return this.childrenOfType(Ge.TYPE)}}const Vi=d.z.object({start:s.n.z,end:s.n.z});class zn extends p.Leaf{static TYPE="range-annotation";schema=Vi;afterUpdate(e){this.internal.render=p.Context.use(e),this.internal.draw=new Ze(this.internal.render.upper2d,p.use(e))}}const gu=p.Xm.payloadZ.extend({viewport:s.W.bounds}),Gi=d.z.object({cursor:s.J.xy.or(d.z.null()),hovered:gu.or(d.z.null()),count:d.z.number()});let Bt=class extends p.Leaf{static TYPE="range-provider";schema=Gi;fetchedInitial=s.w.ZERO;afterUpdate(e){const{internal:n}=this;n.render=p.Context.use(e),n.draw=new Ze(n.render.upper2d,p.use(e)),n.requestRender=Ht(e),n.runAsync=p.useErrorHandler(e),n.ranges??=new Map;const r=Ae(e);n.requestRender("tool"),r!=null&&(n.client=r,n.removeListener=Uu(e,[{channel:p.Xm.SET_CHANNEL_NAME,onChange:dn(p.Xm.payloadZ,async({changed:i})=>{n.client!=null&&(s.ir.isCrude(i.color)&&n.ranges.set(i.key,n.client.ranges.sugarOne(i)),this.setState(a=>({...a,count:n.ranges.size})),n.requestRender("tool"))})},{channel:p.Xm.DELETE_CHANNEL_NAME,onChange:dn(p.Xm.keyZ,async({changed:i})=>{n.ranges.delete(i),this.setState(a=>({...a,count:n.ranges.size})),n.requestRender("tool")})}],n.removeListener))}fetchInitial(e){const{internal:n}=this,{client:r,runAsync:i}=n;r==null||this.fetchedInitial.equals(e,s.a.minutes(1))||(this.fetchedInitial=e,i(async()=>{(await r.ranges.retrieve(e)).forEach(o=>{s.ir.isCrude(o.color)&&n.ranges.set(o.key,o)}),this.setState(o=>({...o,count:n.ranges.size}))},"failed to fetch initial ranges"))}render(e){const{dataToDecimalScale:n,region:r,viewport:i,timeRange:a}=e;this.fetchInitial(a);const{draw:o,ranges:l}=this.internal,u=n.scale(s.$t.xBounds(r)),c=this.state.cursor==null?null:this.state.cursor.x;let h=null;const f=o.canvas.scissor(s.$t.construct({x:s.$t.left(r),y:s.$t.top(r)-35},{x:s.$t.right(r),y:s.$t.bottom(r)}));l.forEach(g=>{const v=s.ir.colorZ.safeParse(g.color);if(!v.success)return;const w=v.data;let b=u.pos(Number(g.timeRange.start.valueOf()));const S=u.pos(Number(g.timeRange.end.valueOf()));if(S<s.$t.left(r)||b>s.$t.right(r))return;b=s.R(b,s.$t.left(r)-2,s.$t.right(r)-1);let R=!1;c!=null&&(R=s.W.contains({lower:b,upper:S},c)),R&&(h={key:g.key,parent:g.parent,name:g.name,color:g.color,labels:g.labels,timeRange:g.timeRange,viewport:{lower:n.scale(s.$t.xBounds(i)).pos(Number(g.timeRange.start.valueOf())),upper:n.scale(s.$t.xBounds(i)).pos(Number(g.timeRange.end.valueOf()))}}),o.container({region:s.$t.construct({x:b,y:s.$t.top(r)-1},{x:S,y:s.$t.bottom(r)-1}),backgroundColor:s.ir.setAlpha(w,.2),bordered:!1});const L=s.$t.construct({x:b+1,y:s.$t.top(r)-34},{x:S-1,y:s.$t.top(r)-12});o.container({region:L,backgroundColor:s.$t.width(L)<20?s.ir.setAlpha(w,.4):k=>R?k.colors.gray.l2:k.colors.gray.l0,bordered:!0,borderWidth:1,borderRadius:2,borderColor:s.ir.setAlpha(w,.8)}),o.text({text:g.name,position:{x:b+8,y:s.$t.top(r)-30},level:"small",shade:10,weight:500,maxWidth:S-b-16})}),f(),h!=null?this.setState(g=>({...g,hovered:h})):this.state.hovered&&this.setState(g=>({...g,hovered:null}))}};const mu={[zn.TYPE]:zn,[Bt.TYPE]:Bt},yu=ot;class Ut extends Hi{static TYPE="XAxis";schema=ot;render(e){if(this.deleted)return;const[n,r]=this.dataToDecimalScale(e.hold,this.dataBounds.bind(this),e.viewport);if(this.renderAxis(e,n.reverse()),this.renderYAxes(e,n),this.renderRangeAnnotations(e,n),r!=null)throw r}findByXDecimal(e,n){const[r,i]=this.dataToDecimalScale(e.hold,this.dataBounds.bind(this),e.viewport);if(i!=null)throw i;return this.findByXValue(e,r.reverse().pos(n))}findByXValue(e,n){const[r,i]=this.dataToDecimalScale(e.hold,this.dataBounds.bind(this),e.viewport);if(i!=null)throw i;const a={...e,xDataToDecimalScale:r};return this.yAxes.map(o=>o.findByXValue(a,n)).flat()}renderYAxes(e,n){const r={...e,xDataToDecimalScale:n};this.yAxes.forEach(i=>i.render(r))}get yAxes(){return this.childrenOfType(Nt.TYPE)}get rangeAnnotations(){return this.childrenOfType(Bt.TYPE)}bounds(e){const[n,r]=this.iBounds(e,this.dataBounds.bind(this));if(r!=null)throw r;return n}renderRangeAnnotations(e,n){const r=this.bounds(e.hold);this.rangeAnnotations.forEach(i=>i.render({dataToDecimalScale:n,region:e.plot,viewport:e.viewport,timeRange:new s.w(r.lower,r.upper)}))}dataBounds(){return this.yAxes.map(e=>e.xBounds())}}const vu=s.J.construct(12),bu=3,Su=14,xu=s.J.construct(6),xr=d.z.object({position:s.J.xy.or(d.z.null()),textColor:s.ir.colorZ.optional().default(s.ir.ZERO),backgroundColor:s.ir.colorZ.optional().default(s.ir.ZERO),borderColor:s.ir.colorZ.optional().default(s.ir.ZERO),ruleColor:s.ir.colorZ.optional().default(s.ir.ZERO),ruleStrokeWidth:d.z.number().optional().default(1),ruleStrokeDash:d.z.number().default(0)});class Xe extends p.Leaf{static TYPE="tooltip";schema=xr;afterUpdate(e){const n=p.use(e);s.ir.isZero(this.state.textColor)&&(this.state.textColor=n.colors.text),s.ir.isZero(this.state.backgroundColor)&&(this.state.backgroundColor=n.colors.gray.l1),s.ir.isZero(this.state.borderColor)&&(this.state.borderColor=n.colors.border),s.ir.isZero(this.state.ruleColor)&&(this.state.ruleColor=n.colors.gray.l7),this.internal.dotColor=n.colors.text,this.internal.dotColorContrast=n.colors.textInverted,this.internal.render=p.Context.use(e),this.internal.draw=new Ze(this.internal.render.upper2d,n),X(e,"tool")}afterDelete(e){X(e,"tool")}render(e){if(this.deleted||this.state.position==null)return;const{region:n}=e,r=s.C.XY.scale(s.$t.DECIMAL).scale(n),i=s.C.XY.scale(n).scale(s.$t.DECIMAL),a=e.findByXDecimal(i.x.pos(this.state.position.x)),o=a.filter(b=>s.J.isFinite(b.value)),{draw:l}=this.internal,u=o.reduce((b,S)=>b+S.position.x,0)/o.length,c=new s.n(o.reduce((b,S)=>b+S.value.x,0)/o.length),h=r.x.pos(u);if(!s.W.contains(s.$t.xBounds(n),h))return;l.rule({stroke:this.state.ruleColor,lineWidth:this.state.ruleStrokeWidth,lineDash:this.state.ruleStrokeDash,direction:"y",region:n,position:h}),o.forEach(b=>{const S=r.pos(b.position);l.circle({fill:s.ir.setAlpha(b.color,.5),radius:8,position:S}),l.circle({fill:s.ir.setAlpha(b.color,.8),radius:5,position:S}),l.circle({fill:s.ir.pickByContrast(b.color,this.internal.dotColor,this.internal.dotColorContrast),radius:2,position:S})});const f=i.pos(this.state.position),g={...s.K.TOP_LEFT};f.x>.6&&(g.x="right"),f.y>.6&&(g.y="bottom");let v=a.reduce((b,S)=>Math.max(b,S.label?.length??0),0);const w=c.fString("preciseDate","local").length;w>v&&(v=w),l.list({root:g,offset:vu,length:o.length+1,padding:xu,itemHeight:Su,spacing:bu,width:v*7+48,position:this.state.position,draw:(b,S)=>{let R="",L="",k=this.state.textColor;if(b===0)R="Time",L=c.fString("preciseDate","local");else{const O=o[b-1];R=O.label??"",L=s.nr.roundBySpan(O.value.y,O.bounds).toString(),k=O.color}l.text({position:s.$t.topLeft(S),text:R,level:"small",weight:500,color:k}),l.text({position:s.J.translateY(s.$t.topRight(S),-1),text:L,level:"small",justify:"right",code:!0,shade:10})}})}}const Xi={[Xe.TYPE]:Xe},wu=Object.freeze(Object.defineProperty({__proto__:null,REGISTRY:Xi,Tooltip:Xe,tooltipStateZ:xr},Symbol.toStringTag,{value:"Module"})),wr=d.z.object({one:s.J.xy.nullable(),two:s.J.xy.nullable(),hover:s.J.xy.nullable(),color:d.z.union([s.ir.colorZ,d.z.object({verticalLine:s.ir.colorZ.optional().default(s.ir.ZERO),horizontalLine:s.ir.colorZ.optional().default(s.ir.ZERO),obliqueLine:s.ir.colorZ.optional().default(s.ir.ZERO)})]).optional().default(s.ir.ZERO),strokeWidth:d.z.number().optional().default(1),strokeDash:d.z.number().optional().default(2)});class Ke extends p.Leaf{static TYPE="measure";schema=wr;afterUpdate(e){const n=p.Context.use(e);this.internal.theme=p.use(e),this.internal.renderCtx=n,this.internal.draw=new Ze(n.upper2d,this.internal.theme),X(e,"tool")}afterDelete(e){X(e,"layout")}get verticalLineColor(){return s.ir.isColor(this.state.color)?s.ir.isZero(this.state.color)?this.internal.theme.colors.gray.l8:this.state.color:s.ir.isZero(this.state.color.verticalLine)?this.internal.theme.colors.gray.l8:this.state.color.verticalLine}get horizontalLineColor(){return s.ir.isColor(this.state.color)?s.ir.isZero(this.state.color)?this.internal.theme.colors.gray.l8:this.state.color:s.ir.isZero(this.state.color.horizontalLine)?this.internal.theme.colors.gray.l8:this.state.color.horizontalLine}get obliqueLineColor(){return s.ir.isColor(this.state.color)?s.ir.isZero(this.state.color)?this.internal.theme.colors.gray.l8:this.state.color:s.ir.isZero(this.state.color.obliqueLine)?this.internal.theme.colors.gray.l8:this.state.color.obliqueLine}find(e){const{one:n,two:r}=this.state;if(n==null||r==null)return null;const{one:i,two:a}=this.prevState,{dataOne:o,dataTwo:l}=this.internal;if(i!=null&&s.J.equals(n,i)&&a!=null&&s.J.equals(r,a)&&o!=null&&l!=null){const[b,S]=[e.findByXValue(o.x),e.findByXValue(l.x)];return b.length===0||S.length===0?null:[b.sort((R,L)=>s.J.distance(o,R.value)-s.J.distance(o,L.value))[0],S.sort((R,L)=>s.J.distance(l,R.value)-s.J.distance(l,L.value))[0]]}const u=s.C.XY.scale(e.region).scale(s.$t.DECIMAL),[c,h]=[u.pos(n),u.pos(r)],[f,g]=[e.findByXDecimal(c.x),e.findByXDecimal(h.x)];if(f.length===0||g.length===0)return null;const[v,w]=[f.sort((b,S)=>s.J.distance(c,b.position)-s.J.distance(c,S.position))[0],g.sort((b,S)=>s.J.distance(h,b.position)-s.J.distance(h,S.position))[0]];return this.internal.dataOne=v.value,this.internal.dataTwo=w.value,[v,w]}renderHover(e){if(this.state.hover==null)return;const n=this.state.hover,r=s.C.XY.scale(e.region).scale(s.$t.DECIMAL),i=r.pos(n),a=e.findByXDecimal(r.pos(n).x);if(a.length===0)return;const o=a.sort((u,c)=>s.J.distance(i,u.position)-s.J.distance(i,c.position))[0],{draw:l}=this.internal;l.circle({fill:s.ir.setAlpha(o.color,.5),radius:9,position:r.reverse().pos(o.position)})}render(e){if(this.deleted)return;this.renderHover(e);const n=this.find(e);if(n==null)return;const[r,i]=n,{draw:a}=this.internal,{strokeDash:o,strokeWidth:l}=this.state,u=s.C.XY.scale(s.$t.DECIMAL).scale(e.region),c=u.pos(r.position),h=u.pos(i.position),f=new s.a(Math.abs(r.value.x-i.value.x)),g=Math.abs(r.value.y-i.value.y),v=g/f.seconds;a.line({start:s.J.construct(c.x,c.y),end:s.J.construct(c.x,h.y),stroke:this.verticalLineColor,lineDash:o,lineWidth:l}),a.textContainer({text:[`${g.toFixed(2)} ${r.units??""}`],direction:"x",position:s.J.construct(c.x,(c.y+h.y)/2),level:"small"}),a.line({start:s.J.construct(c.x,h.y),end:s.J.construct(h.x,h.y),stroke:this.horizontalLineColor,lineDash:o,lineWidth:l}),a.textContainer({text:[f.truncate(s.a.MILLISECOND).toString()],direction:"x",position:s.J.construct((c.x+h.x)/2,h.y),level:"small"}),a.line({start:s.J.construct(c.x,c.y),end:s.J.construct(h.x,h.y),stroke:this.obliqueLineColor,lineDash:o,lineWidth:l}),a.textContainer({text:[`${v.toFixed(2)} ${r.units??""} / S`],direction:"x",position:s.J.construct((c.x+h.x)/2,(c.y+h.y)/2),level:"small"}),a.circle({fill:s.ir.setAlpha(r.color,.5),radius:8,position:c}),a.circle({fill:s.ir.setAlpha(r.color,.8),radius:5,position:c}),a.circle({fill:s.ir.WHITE,radius:2,position:c}),a.circle({fill:s.ir.setAlpha(i.color,.5),radius:8,position:h}),a.circle({fill:s.ir.setAlpha(i.color,.8),radius:5,position:h}),a.circle({fill:s.ir.WHITE,radius:2,position:h})}}const Ki={[Ke.TYPE]:Ke},Tu=Object.freeze(Object.defineProperty({__proto__:null,Measure:Ke,REGISTRY:Ki,measureStateZ:wr},Symbol.toStringTag,{value:"Module"})),Qi=d.z.object({container:s.$t.box,viewport:s.$t.box,hold:d.z.boolean().optional().default(!1),grid:d.z.record(d.z.string(),xi),visible:d.z.boolean().optional().default(!0),clearOverScan:s.J.crudeZ.optional().default(s.J.ZERO)}),Eu=(t,e)=>{const n=s.$t.width(t)*Math.sqrt(s.$t.height(t)),r=s.$t.width(e)*Math.sqrt(s.$t.height(e));return n/r},Cu=["upper2d","lower2d","gl"],Pu=["upper2d"];class An extends p.Composite{static TYPE="LinePlot";schema=Qi;afterUpdate(e){this.internal.instrumentation=p.useInstrumentation(e,"lineplot"),this.internal.handleError=p.useErrorHandler(e),this.internal.renderCtx=p.Context.use(e),Wt(e,n=>{this.state.visible&&this.requestRender("low",n)}),!(!this.state.visible&&!this.prevState.visible)&&this.requestRender("high","layout")}afterDelete(e){this.internal.renderCtx=p.Context.use(e),this.requestRender("high","layout")}findByXDecimal(e){const n={...this.state,plot:this.calculatePlot(),exposure:this.exposure};return this.axes.flatMap(r=>r.findByXDecimal(n,e)).flat()}findByXValue(e){const n={...this.state,plot:this.calculatePlot(),exposure:this.exposure};return this.axes.flatMap(r=>r.findByXValue(n,e)).flat()}get axes(){return this.childrenOfType(Ut.TYPE)}get tooltips(){return this.childrenOfType(Xe.TYPE)}get measures(){return this.childrenOfType(Ke.TYPE)}get bounds(){return this.childrenOfType(Ot.TYPE)}get exposure(){return Eu(this.state.viewport,this.state.container)}renderAxes(e,n){const r={...this.state,plot:e,canvases:n,exposure:this.exposure};this.axes.forEach(i=>i.render(r))}renderTooltips(e,n){const r={findByXDecimal:this.findByXDecimal.bind(this),region:e,canvases:n};this.tooltips.forEach(i=>i.render(r))}renderBounds(){this.bounds.forEach(e=>e.render({getBounds:()=>{const n={};return this.axes.forEach(r=>{const i=r.state.axisKey??r.key;n[i]=r.bounds(this.state.hold),r.yAxes.forEach(a=>{const o=a.state.axisKey??a.key;n[o]=a.bounds(this.state.hold)})}),n}}))}renderMeasures(e){const n={findByXDecimal:this.findByXDecimal.bind(this),findByXValue:this.findByXValue.bind(this),region:e};this.measures.forEach(r=>r.render(n))}calculatePlot(){return $o(this.state.grid,this.state.container)}render(e){const{instrumentation:n,renderCtx:r,handleError:i}=this.internal;if(this.deleted){n.L.debug("deleted, skipping render",{key:this.key});return}if(!this.state.visible)return n.L.debug("not visible, skipping render",{key:this.key}),({canvases:h})=>r.erase(this.state.container,this.state.clearOverScan,...h);const a=this.calculatePlot();n.L.debug("rendering",{key:this.key,viewport:this.state.viewport,container:this.state.container,grid:this.state.grid,plot:a,canvases:e});const o=s.J.construct(this.state.clearOverScan),l=r.scissor(this.state.container,o,e.filter(h=>h!=="gl")),u=r.scissor(a,s.J.ZERO,e.filter(h=>h==="gl"));try{this.renderAxes(a,e),this.renderTooltips(a,e),this.renderMeasures(a),this.renderBounds()}catch(h){i(h,"failed to render line plot")}finally{l(),u()}n.L.debug("rendered",{key:this.key});const c=s.$t.copy(this.state.container);return({canvases:h})=>r.erase(c,this.state.clearOverScan,...h)}requestRender(e,n){const{renderCtx:r}=this.internal;let i=Cu;n==="tool"&&(i=Pu),r.loop.set({key:`${this.type}-${this.key}`,render:()=>this.render(i),priority:e,canvases:i})}}const ku={[An.TYPE]:An,[Ut.TYPE]:Ut,[Nt.TYPE]:Nt,[Ot.TYPE]:Ot},ea=d.z.object({region:s.$t.box,wheelPos:d.z.number(),scrolling:d.z.boolean(),empty:d.z.boolean(),visible:d.z.boolean(),telem:gt.optional().default(ds),font:p.levelZ.optional().default("p"),color:s.ir.colorZ.optional().default(s.ir.ZERO),overshoot:s.J.xy.optional().default({x:0,y:0})}),Ru=.98,qe="lower2d",Mu={offset:0n,offsetRef:0n,scrollRef:0};class Qe extends p.Leaf{static TYPE="log";static z=ea;schema=Qe.z;values=new s.Vt([]);scrollState=Mu;afterUpdate(e){const{internal:n}=this;n.render=p.Context.use(e),n.theme=p.use(e),s.ir.isZero(this.state.color)?this.internal.textColor=n.theme.colors.gray.l11:n.textColor=this.state.color,n.telem=F(e,this.state.telem,n.telem);const{scrolling:r,wheelPos:i}=this.state;if(this.state.scrolling&&!this.prevState.scrolling){const u=this.values.alignmentBounds.upper-1n;this.scrollState={offset:u,offsetRef:u,scrollRef:this.state.wheelPos}}else if(r){const{scrollState:u,values:c}=this,h=Math.ceil((i-this.scrollState.scrollRef)/this.lineHeight);u.offset=this.values.traverseAlignment(u.offsetRef,-BigInt(h)),u.offset<c.alignmentBounds.lower+BigInt(this.visibleLineCount)&&(u.offset=c.alignmentBounds.lower,this.setState(f=>({...f,wheelPos:this.prevState.wheelPos}))),u.offset>=c.alignmentBounds.upper&&this.setState(f=>({...f,scrolling:!1}))}const[o,l]=this.internal.telem.value();this.values=l,this.checkEmpty(),n.stopListeningTelem?.(),n.stopListeningTelem=n.telem.onChange(()=>{const[u,c]=this.internal.telem.value();this.checkEmpty(),this.values=c,this.requestRender()}),!(!this.state.visible&&!this.prevState.visible)&&this.requestRender()}checkEmpty(){const e=this.values.length===0;e!==this.state.empty&&this.setState(n=>({...n,empty:e}))}afterDelete(){const{telem:e,render:n}=this.internal;e.cleanup?.(),n.erase(s.$t.construct(this.state.region),s.J.ZERO,qe)}requestRender(){const{render:e}=this.internal;e.loop.set({key:`${this.type}-${this.key}`,render:()=>this.render(),priority:"high",canvases:[qe]})}get lineHeight(){return this.internal.theme.typography[this.state.font].size*this.internal.theme.sizes.base}get totalHeight(){return Math.ceil(this.values.length*this.lineHeight)}get visibleLineCount(){return Math.min(Math.floor((s.$t.height(this.state.region)-12)/this.lineHeight),this.values.length)}render(){const{render:e}=this.internal,n=this.state.region;if(s.$t.areaIsZero(n))return;if(!this.state.visible)return()=>e.erase(n,s.J.ZERO,qe);let r;if(!this.state.scrolling)r=this.values.subIterator(this.values.length-this.visibleLineCount,this.values.length);else{const c=this.values.traverseAlignment(this.scrollState.offset,-BigInt(this.visibleLineCount));r=this.values.subAlignmentSpanIterator(c,this.visibleLineCount)}const i=this.state.region,a=e[qe],o=new Ze(a,this.internal.theme),l=e.scissor(i,s.J.ZERO,[qe]);this.renderElements(o,r),this.renderScrollbar(o),l();const u=s.$t.copy(this.state.region);return({canvases:c})=>e.erase(u,this.state.overshoot,...c)}renderScrollbar(e){const n=this.state.region,r=s.$t.height(n)/this.totalHeight*s.$t.height(n);if(r>=s.$t.height(n)*Ru)return;let i=s.$t.bottom(n)-r;this.state.scrolling&&(i-=Number(this.values.distance(this.values.alignmentBounds.upper,this.scrollState.offset))/this.values.length*s.$t.height(n)),i<0&&(i=s.$t.top(n)),e.container({region:s.$t.construct({x:s.$t.right(n)-6,y:i},{width:6,height:r}),bordered:!1,backgroundColor:a=>a.colors.gray.l6})}renderElements(e,n){const r=this.state.region;let i=0;for(const a of n){const o=this.values.dataType.equals(s.r.JSON)?JSON.stringify(a):a.toString();e.text({text:o,level:this.state.font,shade:11,position:s.J.translate(s.$t.topLeft(r),{x:6,y:i*this.lineHeight+6}),code:!0}),i++}}}const Lu={[Qe.TYPE]:Qe},ta=d.z.object({trigger:d.z.number(),command:d.z.number().optional(),value:d.z.number(),sink:ys.optional().default(cs),source:ms.optional().default(us)});class Zn extends p.Leaf{static TYPE="Setpoint";schema=ta;afterUpdate(e){const{sink:n,source:r,trigger:i,command:a}=this.state,{internal:o}=this;o.prevTrigger??=i,(async()=>{this.internal.source=F(e,r,this.internal.source),o.sink=rt(e,n,o.sink);const l=o.prevTrigger;o.prevTrigger=i,i>l&&a!=null&&this.internal.sink.set(a),this.updateValue(),o.stopListening?.(),o.stopListening=o.source.onChange(()=>this.updateValue())})()}updateValue(){const e=this.internal.source.value();e!==this.state.value&&this.setState(n=>({...n,value:e,triggered:!1}))}afterDelete(){const{internal:e}=this;e.stopListening(),e.source.cleanup?.(),e.sink.cleanup?.()}}const Ou={[Zn.TYPE]:Zn},na=d.z.object({triggered:d.z.boolean(),enabled:d.z.boolean(),sink:Gt.optional().default(Jt),source:Wn.optional().default(qn)});class In extends p.Leaf{static TYPE="Toggle";schema=na;afterUpdate(e){this.internal.addStatus=p.useOptionalAdder(e);const{sink:n,source:r,triggered:i,enabled:a}=this.state,{triggered:o}=this.prevState,{internal:l}=this;l.source=F(e,r,l.source),l.sink=rt(e,n,l.sink),i&&!o&&l.sink.set(!a),this.updateEnabledState(),l.stopListening?.(),l.stopListening=l.source.onChange(()=>this.updateEnabledState())}updateEnabledState(){const e=this.internal.source.value();e!==this.state.enabled&&this.setState(n=>({...n,enabled:e,triggered:!1}))}afterDelete(){this.internal.stopListening(),this.internal.source.cleanup?.(),this.internal.sink.cleanup?.()}}const Yu={[In.TYPE]:In},hn={useAtlas:!0},$u=d.z.object({box:s.$t.box,telem:jn.optional().default(hs),backgroundTelem:Hn.optional().default(jt),level:p.levelZ.optional().default("p"),color:s.ir.colorZ.optional().default(s.ir.ZERO),precision:d.z.number().optional().default(2),minWidth:d.z.number().optional().default(60),width:d.z.number().optional(),notation:s.mr.notationZ.optional().default("standard"),location:s.K.xy.optional().default({x:"left",y:"center"}),useWidthForBackground:d.z.boolean().optional().default(!1),valueBackgroundShift:s.J.xy.optional().default(s.J.ZERO),valueBackgroundOverScan:s.J.xy.optional().default(s.J.ZERO)}),Du=["upper2d","lower2d"];class ze extends p.Leaf{static TYPE="value";static z=$u;schema=ze.z;afterUpdate(e){const{internal:n}=this;n.renderCtx=p.Context.use(e),n.theme=p.use(e),s.ir.isZero(this.state.color)?n.textColor=n.theme.colors.gray.l10:n.textColor=this.state.color,n.telem=F(e,this.state.telem,n.telem),n.stopListening?.(),n.stopListening=n.telem.onChange(()=>this.requestRender()),n.fontString=Fe.fontString(n.theme,{level:this.state.level,code:!0}),n.backgroundTelem=F(e,this.state.backgroundTelem,n.backgroundTelem),n.stopListeningBackground?.(),n.stopListeningBackground=n.backgroundTelem.onChange(()=>this.requestRender()),n.requestRender=ss(e),this.requestRender()}afterDelete(){const{internal:e}=this;e.stopListening?.(),e.stopListeningBackground?.(),e.telem.cleanup?.(),e.backgroundTelem.cleanup?.(),e.requestRender==null?e.renderCtx.erase(s.$t.construct(this.state.box),s.J.ZERO,...Du):e.requestRender("layout")}requestRender(){const{requestRender:e}=this.internal;e!=null?e("layout"):this.render({})}get fontHeight(){const{theme:e}=this.internal;return e.typography[this.state.level].size*e.sizes.base}maybeUpdateWidth(e){const{theme:n}=this.internal,r=e+n.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)}))}render({viewportScale:e=s.C.XY.IDENTITY}){const{renderCtx:n,telem:r,backgroundTelem:i,fontString:a,requestRender:o}=this.internal,{location:l,box:u}=this.state;if(s.$t.areaIsZero(u))return;const c=s.$t.topLeft(u),h=s.$t.width(u),f=s.$t.height(u),g=n.lower2d.applyScale(e);let v=r.value();g.font=a;const w=this.fontHeight,b=v[0]=="-";b&&(v=v.slice(1));const{theme:S}=this.internal,R=g.textDimensions(v,hn),L=R.width+S.sizes.base,k=R.height;o==null&&n.erase(s.$t.construct(this.prevState.box)),this.maybeUpdateWidth(L);const O={...s.J.ZERO};l.x==="left"?O.x=6+w*.75:l.x==="center"&&(O.x=h/2-L/2),l.y==="center"&&(O.y=f/2+k/2);const $=s.J.translate(c,O);let x=!0;if(this.state.backgroundTelem.type!=jt.type){const Y=i.value();if(!s.ir.isZero(Y)){x=!1,g.fillStyle=s.ir.hex(Y);const Ie=this.state.useWidthForBackground?this.state.width??this.state.minWidth:s.$t.width(u);g.fillRect(...s.J.couple(s.J.translate(c,this.state.valueBackgroundShift)),Ie+this.state.valueBackgroundOverScan.x,f+this.state.valueBackgroundOverScan.y);const pe=s.ir.pickByContrast(Y,S.colors.gray.l0,S.colors.gray.l11);g.fillStyle=s.ir.hex(pe)}}x&&(g.fillStyle=s.ir.hex(this.internal.textColor)),b&&g.fillText("-",...s.J.couple(s.J.translateX($,-w*.6)),void 0,hn),g.fillText(v,...s.J.couple($),void 0,hn)}}const ra={[ze.TYPE]:ze},_u=Object.freeze(Object.defineProperty({__proto__:null,REGISTRY:ra,Value:ze},Symbol.toStringTag,{value:"Module"})),zu=(t,e)=>{const n=t.includes("delete"),r=e.includes("delete");return n&&!r?-1:!n&&r?1:0};class sa{handlers=new Map;streamerMutex=s.wr.newMutex({streamer:null});handleError;debouncedRemoveHandler;openStreamer=null;constructor({handleError:e,removalDelay:n=0}){this.handleError=e,this.debouncedRemoveHandler=p.o(r=>{this.handleError(this.updateStreamer.bind(this),`Failed to remove ${r} from the Sync.Provider streamer`)},s.a.fromMilliseconds(n).milliseconds)}handleChange(e){const n=[...e.uniqueNames];n.sort(zu),n.forEach(r=>{this.handlers.forEach((i,a)=>{if(i===r)try{a(e)}catch(o){this.handleError(o,`Error calling Sync Frame Handler on channel(s): ${i}`)}})})}async close(){return await this.streamerMutex.runExclusive(this.unprotectedClose.bind(this))}async unprotectedClose(){const e=this.streamerMutex.streamer;this.streamerMutex.streamer=null,e!=null&&await e.close(),this.handlers.clear(),this.openStreamer=null}async updateStreamer(e){await this.streamerMutex.runExclusive(async()=>{if(e!=null&&(this.openStreamer=e),this.openStreamer==null)return;const n=new Set(this.handlers.values()),r=this.streamerMutex.streamer;if(r!=null)return n.size===0?await this.unprotectedClose():await r.update(Array.from(n));if(n.size===0)return;const i=await p.Pm.HardenedStreamer.open(this.openStreamer,Array.from(n));this.streamerMutex.streamer=new p.Pm.ObservableStreamer(i),this.streamerMutex.streamer.onChange(this.handleChange.bind(this))})}addListener(e,n,r){const i=new Set(this.handlers.values());return this.handlers.set(e,n),i.has(n)||this.handleError(async()=>{await this.updateStreamer(),r?.()},`Failed to add ${n} to the Sync.Provider streamer`),()=>{this.handlers.delete(e),this.debouncedRemoveHandler(n)}}}const ia=d.object({}),Au={addListener:null},qt="flux-context",Zu=(t,e)=>t.set(qt,e);class et extends p.Composite{static TYPE="flux.Provider";static stateZ=ia;schema=et.stateZ;afterUpdate(e){const{internal:n}=this;e.wasSetPreviously(qt)||Zu(e,Au);const r=Ae(e),i=p.useErrorHandler(e);if(n.streamer??=new sa({handleError:i}),r==null)return;i(async()=>await n.streamer.updateStreamer(r.openStreamer.bind(r)),"Failed to update Flux.Provider streamer");const a={addListener:({channel:o,handler:l,onOpen:u})=>n.streamer.addListener(l,o,u)};e.set(qt,a)}}const Iu={[et.TYPE]:et},Nu=()=>()=>{},Bu=t=>t.get(qt).addListener??Nu,aa=(t,e,n)=>{const r=p.t.toArray(n).map(({channel:i,onChange:a})=>t({channel:i,handler:o=>{e(async()=>await a({changed:o.get(i)}),`Error in Flux.useListener on channel ${i}`)}}));return()=>r.forEach(i=>i())},Uu=(t,e,n)=>{if(n!=null)return n;const r=Bu(t),i=p.useErrorHandler(t);return aa(r,i,e)};exports.AcquireChannelControl=kt;exports.Annotation=zn;exports.AuthoritySource=Rt;exports.Base=fe;exports.BaseProvider=Oe;exports.Bottom=Bi;exports.BoundQuerier=Ot;exports.Button=Pn;exports.Canvas=Lt;exports.Chip=wn;exports.Controller=Tn;exports.Diagram=Mo;exports.Diagram$1=le;exports.Indicator=En;exports.Legend=Cn;exports.Light=kn;exports.Line=Mt;exports.LinePlot=An;exports.Log=Qe;exports.MODES=di;exports.MOUSE_DOWN_INCREMENT=pi;exports.MOUSE_UP_INCREMENT=gi;exports.Measure=Ke;exports.Mutex=as;exports.Provider=pt;exports.Provider$1=et;exports.Provider$2=Bt;exports.REGISTRY=ku;exports.REGISTRY$1=Iu;exports.REGISTRY$10=ji;exports.REGISTRY$11=mu;exports.REGISTRY$12=Ki;exports.REGISTRY$13=Eo;exports.REGISTRY$14=Lo;exports.REGISTRY$15=vi;exports.REGISTRY$16=co;exports.REGISTRY$17=yi;exports.REGISTRY$18=ho;exports.REGISTRY$2=ka;exports.REGISTRY$3=Lu;exports.REGISTRY$4=ra;exports.REGISTRY$5=Xi;exports.REGISTRY$6=Yu;exports.REGISTRY$7=Ks;exports.REGISTRY$8=ls;exports.REGISTRY$9=Ou;exports.Right=qi;exports.Rule=Ge;exports.STATUSES=ri;exports.SetChannelValue=Pt;exports.Setpoint=Zn;exports.StateProvider=We;exports.Streamer=sa;exports.Table=Te;exports.Toggle=In;exports.Tooltip=Xe;exports.Top=Ui;exports.Value=ze;exports.XAxis=Ut;exports.YAxis=Nt;exports.ZERO_CONTEXT_VALUE=Bn;exports.a=Ft;exports.acquireChannelControl=ao;exports.acquireChannelControlPropsZ=oi;exports.aether=du;exports.annotationStateZ=Vi;exports.authoritySource=lo;exports.authoritySourceDetailsZ=oo;exports.authoritySourceProps=li;exports.axisStateZ=br;exports.boundQuerierStateZ=Si;exports.buttonStateZ=fi;exports.canvas=Ro;exports.canvasStateZ=ar;exports.channelData=Es;exports.chipStateZ=ei;exports.chipStatusDetailsZ=Qs;exports.color=Ye;exports.colorGradient=Ns;exports.control=Wt;exports.controllerStateZ=ii;exports.coreAxisStateZ=ot;exports.diagramStateZ=or;exports.external=so;exports.indicatorStateZ=ui;exports.indicatorStatusDetailsZ=ci;exports.interpolate=en;exports.interpolateNumber=je;exports.interpolateRgb=On;exports.interpolateString=Pi;exports.legendStateZ=hi;exports.lightStateZ=bi;exports.linePlotStateZ=Qi;exports.logState=ea;exports.measure=Tu;exports.measureStateZ=wr;exports.mountListeners=aa;exports.newCanvas=Ni;exports.newTickFactory=Dn;exports.parseAutoBounds=Ji;exports.parsedHandler=dn;exports.provider=Ca;exports.providerStateZ=ia;exports.providerStateZ$1=Gi;exports.providerStateZ$2=ir;exports.regions=ie;exports.request=X;exports.rollingAverage=Zs;exports.rollingAverageProps=rr;exports.ruleStateZ=Sr;exports.scaleNumber=Us;exports.setChannelValue=io;exports.setChannelValuePropsZ=ai;exports.setpoint=$s;exports.setpointStateZ=ta;exports.sinkPipeline=xs;exports.sinkPipelinePropsZ=Kn;exports.sourcePipeline=Ss;exports.sourcePipelinePropsZ=Gn;exports.stateProviderStateZ=ti;exports.stateZ=mi;exports.statusZ=si;exports.streamChannelData=Cs;exports.streamChannelValue=Ps;exports.streamChannelValuePropsZ=Qn;exports.stringHandler=va;exports.stringSourceSpecZ=jn;exports.stringifyNumber=As;exports.stringifyNumberProps=nr;exports.sugaredStateZ=ni;exports.tickFactoryProps=vr;exports.tickType=yr;exports.toggleStateZ=na;exports.tooltip=wu;exports.tooltipStateZ=xr;exports.useOptionalRequestor=ss;exports.useRequestor=Ht;exports.value=_u;exports.withinBounds=Ds;exports.withinBoundsProps=tr;exports.withinSizeThreshold=Fi;exports.xAxisStateZ=yu;exports.yAxisStateZ=fu;