@synnaxlabs/pluto 0.52.5 → 0.52.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/ether.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("./provider-DQkVj3tA.cjs"),e=require("./value-Bfn0uQuG.cjs"),R=require("@synnaxlabs/alamos"),l=require("@synnaxlabs/x"),o=require("./eraser-rFMFKqsg.cjs");require("react");require("@synnaxlabs/client");require("./types-DI2vtOGs.cjs");const s=require("./fontString-BNnhiwug.cjs"),E=Object.freeze(Object.defineProperty({__proto__:null,Provider:t.Provider,REGISTRY:t.REGISTRY,SYNNAX_DARK:t.SYNNAX_DARK,SYNNAX_LIGHT:t.SYNNAX_LIGHT,SYNNAX_THEMES:t.SYNNAX_THEMES,fontSpecZ:t.fontSpecZ,fontString:s.fontString,themeZ:t.themeZ,use:t.use},Symbol.toStringTag,{value:"Module"})),T=Object.freeze(Object.defineProperty({__proto__:null,Context:o.Context,GLProgram:o.GLProgram,Loop:o.Loop,control:e.control,request:e.request,useOptionalRequestor:e.useOptionalRequestor,useRequestor:e.useRequestor},Symbol.toStringTag,{value:"Module"})),a=Object.freeze(Object.defineProperty({__proto__:null,LinePlot:e.LinePlot,REGISTRY:e.REGISTRY,XAxis:e.XAxis,YAxis:e.YAxis,linePlotMethodsZ:e.linePlotMethodsZ,linePlotStateZ:e.linePlotStateZ,xAxisStateZ:e.xAxisStateZ,yAxisStateZ:e.yAxisStateZ},Symbol.toStringTag,{value:"Module"})),u={[e.FLUX_STORE_KEY$2]:e.FLUX_STORE_CONFIG$2,[e.RELATIONSHIPS_FLUX_STORE_KEY]:e.RELATIONSHIP_FLUX_STORE_CONFIG,[e.RESOURCES_FLUX_STORE_KEY]:e.RESOURCE_FLUX_STORE_CONFIG,[e.FLUX_STORE_KEY$1]:e.FLUX_STORE_CONFIG$1,[e.FLUX_STORE_KEY]:e.FLUX_STORE_CONFIG},_=()=>{const r=new l.RoutedWorker((n,i)=>postMessage(n,i));onmessage=r.handle.bind(r);const S={...o.REGISTRY$1,...e.REGISTRY$20,...e.REGISTRY$19,...e.REGISTRY$18,...e.REGISTRY$17,...o.REGISTRY,...e.REGISTRY$16,...e.REGISTRY$15,...e.REGISTRY$14,...e.REGISTRY,...e.REGISTRY$13,...e.REGISTRY$12,...e.REGISTRY$11,...e.REGISTRY$10,...e.REGISTRY$9,...t.REGISTRY$1,...e.REGISTRY$8,...e.REGISTRY$7,...t.REGISTRY,...e.REGISTRY$6,...e.REGISTRY$5,...e.REGISTRY$4,...e.REGISTRY$3,...e.REGISTRY$2,...e.REGISTRY$1,...e.createRegistry({storeConfig:u})};t.render({comms:r.route("vis"),registry:S,instrumentation:new R.Instrumentation({logger:new R.Logger({filters:[R.logThresholdFilter("info")]})})})},I=Object.freeze(Object.defineProperty({__proto__:null,render:_},Symbol.toStringTag,{value:"Module"}));exports.aether=t.aether;exports.canvas=e.canvas;exports.diagram=e.Diagram;exports.measure=e.measure;exports.rule=e.aether;exports.synnax=e.provider;exports.telem=e.external;exports.tooltip=e.tooltip;exports.value=e.value;exports.lineplot=a;exports.pluto=I;exports.render=T;exports.theming=E;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("./provider-DQkVj3tA.cjs"),e=require("./value-DJPQ1lb4.cjs"),R=require("@synnaxlabs/alamos"),l=require("@synnaxlabs/x"),o=require("./eraser-rFMFKqsg.cjs");require("react");require("@synnaxlabs/client");require("./types-DI2vtOGs.cjs");const s=require("./fontString-BNnhiwug.cjs"),E=Object.freeze(Object.defineProperty({__proto__:null,Provider:t.Provider,REGISTRY:t.REGISTRY,SYNNAX_DARK:t.SYNNAX_DARK,SYNNAX_LIGHT:t.SYNNAX_LIGHT,SYNNAX_THEMES:t.SYNNAX_THEMES,fontSpecZ:t.fontSpecZ,fontString:s.fontString,themeZ:t.themeZ,use:t.use},Symbol.toStringTag,{value:"Module"})),T=Object.freeze(Object.defineProperty({__proto__:null,Context:o.Context,GLProgram:o.GLProgram,Loop:o.Loop,control:e.control,request:e.request,useOptionalRequestor:e.useOptionalRequestor,useRequestor:e.useRequestor},Symbol.toStringTag,{value:"Module"})),a=Object.freeze(Object.defineProperty({__proto__:null,LinePlot:e.LinePlot,REGISTRY:e.REGISTRY,XAxis:e.XAxis,YAxis:e.YAxis,linePlotMethodsZ:e.linePlotMethodsZ,linePlotStateZ:e.linePlotStateZ,xAxisStateZ:e.xAxisStateZ,yAxisStateZ:e.yAxisStateZ},Symbol.toStringTag,{value:"Module"})),u={[e.FLUX_STORE_KEY$2]:e.FLUX_STORE_CONFIG$2,[e.RELATIONSHIPS_FLUX_STORE_KEY]:e.RELATIONSHIP_FLUX_STORE_CONFIG,[e.RESOURCES_FLUX_STORE_KEY]:e.RESOURCE_FLUX_STORE_CONFIG,[e.FLUX_STORE_KEY$1]:e.FLUX_STORE_CONFIG$1,[e.FLUX_STORE_KEY]:e.FLUX_STORE_CONFIG},_=()=>{const r=new l.RoutedWorker((n,i)=>postMessage(n,i));onmessage=r.handle.bind(r);const S={...o.REGISTRY$1,...e.REGISTRY$20,...e.REGISTRY$19,...e.REGISTRY$18,...e.REGISTRY$17,...o.REGISTRY,...e.REGISTRY$16,...e.REGISTRY$15,...e.REGISTRY$14,...e.REGISTRY,...e.REGISTRY$13,...e.REGISTRY$12,...e.REGISTRY$11,...e.REGISTRY$10,...e.REGISTRY$9,...t.REGISTRY$1,...e.REGISTRY$8,...e.REGISTRY$7,...t.REGISTRY,...e.REGISTRY$6,...e.REGISTRY$5,...e.REGISTRY$4,...e.REGISTRY$3,...e.REGISTRY$2,...e.REGISTRY$1,...e.createRegistry({storeConfig:u})};t.render({comms:r.route("vis"),registry:S,instrumentation:new R.Instrumentation({logger:new R.Logger({filters:[R.logThresholdFilter("info")]})})})},I=Object.freeze(Object.defineProperty({__proto__:null,render:_},Symbol.toStringTag,{value:"Module"}));exports.aether=t.aether;exports.canvas=e.canvas;exports.diagram=e.Diagram;exports.measure=e.measure;exports.rule=e.aether;exports.synnax=e.provider;exports.telem=e.external;exports.tooltip=e.tooltip;exports.value=e.value;exports.lineplot=a;exports.pluto=I;exports.render=T;exports.theming=E;
package/dist/ether.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { P as R, R as s, S, a as n, b as E, f as T, t as i, u as l, c as _, r as I } from "./provider-Bt-E2O6g.js";
2
2
  import { d as Xe } from "./provider-Bt-E2O6g.js";
3
- import { c as G, r as Y, u as m, a as $, L as O, R as a, X as p, Y as u, l as f, b as g, x as c, y as d, d as L, e as F, f as b, g as N, h as X, i as x, j as P, k as y, m as U, n as C, o as A, p as j, q as v, s as h, t as M, v as K, w as Z, z as w, A as z, B as H, C as q, F as k, D, E as W, G as B, H as J, I as Q, J as V, K as ee, M as se, N as ae } from "./value-DimszMFu.js";
4
- import { O as Pe, P as ye, Q as Ue, S as Ce, T as Ae, U as je, V as ve, W as he } from "./value-DimszMFu.js";
3
+ import { c as G, r as Y, u as m, a as $, L as O, R as a, X as p, Y as u, l as f, b as g, x as c, y as d, d as L, e as F, f as b, g as N, h as X, i as x, j as P, k as y, m as U, n as C, o as A, p as j, q as v, s as h, t as M, v as K, w as Z, z as w, A as z, B as H, C as q, F as k, D, E as W, G as B, H as J, I as Q, J as V, K as ee, M as se, N as ae } from "./value-CQ1JSZ3H.js";
4
+ import { O as Pe, P as ye, Q as Ue, S as Ce, T as Ae, U as je, V as ve, W as he } from "./value-CQ1JSZ3H.js";
5
5
  import { Instrumentation as te, Logger as oe, logThresholdFilter as re } from "@synnaxlabs/alamos";
6
6
  import { RoutedWorker as Re } from "@synnaxlabs/x";
7
7
  import { C as Se, G as ne, L as Ee, R as Te, a as ie } from "./eraser-BShvqlBE.js";
package/dist/index.cjs CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const R=require("@synnaxlabs/client"),x=require("@synnaxlabs/x"),ce=require("zod"),T=require("./value-Bfn0uQuG.cjs"),v=require("react"),a=require("./jsx-runtime-nZSsnGb7.cjs"),le=require("./Provider-B1JpVCIg.cjs"),b=require("./Text-_KoMj9Wf.cjs"),X=require("./Editable-HUPqTaui.cjs"),ye=require("./types-DI2vtOGs.cjs"),g=require("./css-CloSmhZB.cjs"),J=require("./Box-CNUz5BsV.cjs"),pe=require("./Tags-BE6wPgNv.cjs"),je=require("./Copy-6Mur4EW2.cjs"),ke=require("./external-C0FbiHkb.cjs"),xt=require("./Items-806FU8Ig.cjs"),dt=require("./Animated-C4AcIYpH.cjs"),ox=require("react-dom"),Ze=require("./Haul-BShXYNxx.cjs"),As=require("./provider-DQkVj3tA.cjs"),_t=require("./external-DUYMFee8.cjs"),J4=require("./useStaticData-BTwIe0Il.cjs"),ic=require("./external-Bzko45Io.cjs"),sx=require("./Animated-BhCfNN8N.cjs"),nt=require("./external-BY9Nw2gP.cjs"),Ys=require("./eraser-rFMFKqsg.cjs"),Xt=require("./event-BxvV3arE.cjs"),Si=require("./external-CROdzUNR.cjs"),Er=require("./hooks-DmaLjPZJ.cjs"),ix=require("./external-ByPmlfc-.cjs"),Rm=require("./dimensions-CdFEW3oU.cjs"),Ei=require("./external-RARODBsH.cjs"),_m=require("./Menu-ZISpSd-o.cjs");;/* empty css */const po=require("./external-qZkew-g7.cjs"),ax=require("./units-Bu36uC6z.cjs"),Q4=require("./external-VtOg79_6.cjs"),Ge=require("./external-9dcu01v6.cjs");require("@synnaxlabs/alamos");const e3=require("./external-BwbypKCk.cjs"),t3=require("./external-DOHVmFq6.cjs"),n3=require("./Video-BryrVNlH.cjs"),lt={present:"rename",past:"renamed",participle:"renaming"},ot={present:"delete",past:"deleted",participle:"deleting"},ac={present:"update",past:"updated",participle:"updating"},Jt={present:"create",past:"created",participle:"creating"},lc={present:"snapshot",past:"snapshotted",participle:"snapshotting"},lx={present:"copy",past:"copied",participle:"copying"},cx={present:"set",past:"set",participle:"setting"},r3={present:"save",past:"saved",participle:"saving"},ux=Symbol(),cc=Symbol(),eo="a",Us="w";let o3=(e,t)=>new Proxy(e,t);const kl=Object.getPrototypeOf,wm=new WeakMap,uc=e=>e&&(wm.has(e)?wm.get(e):kl(e)===Object.prototype||kl(e)===Array.prototype),km=e=>typeof e=="object"&&e!==null,Cm=new WeakMap,dx=e=>e[cc]||e,mx=(e,t,r)=>{if(!uc(e))return e;const o=dx(e),n=(i=>Object.isFrozen(i)||Object.values(Object.getOwnPropertyDescriptors(i)).some(l=>!l.writable))(o);let s=r&&r.get(o);return s&&s[1].f===n||(s=((i,l)=>{const c={f:l};let u=!1;const d=(p,f)=>{if(!u){let h=c[eo].get(i);if(h||(h={},c[eo].set(i,h)),p===Us)h[Us]=!0;else{let y=h[p];y||(y=new Set,h[p]=y),y.add(f)}}},m={get:(p,f)=>f===cc?i:(d("k",f),mx(Reflect.get(p,f),c[eo],c.c)),has:(p,f)=>f===ux?(u=!0,c[eo].delete(i),!0):(d("h",f),Reflect.has(p,f)),getOwnPropertyDescriptor:(p,f)=>(d("o",f),Reflect.getOwnPropertyDescriptor(p,f)),ownKeys:p=>(d(Us),Reflect.ownKeys(p))};return l&&(m.set=m.deleteProperty=()=>!1),[m,c]})(o,n),s[1].p=o3(n?(i=>{let l=Cm.get(i);if(!l){if(Array.isArray(i))l=Array.from(i);else{const c=Object.getOwnPropertyDescriptors(i);Object.values(c).forEach(u=>{u.configurable=!0}),l=Object.create(kl(i),c)}Cm.set(i,l)}return l})(o):o,s[0]),r&&r.set(o,s)),s[1][eo]=t,s[1].c=r,s[1].p},px=(e,t,r,o)=>{if(Object.is(e,t))return!1;if(!km(e)||!km(t))return!0;const n=r.get(dx(e));if(!n)return!0;if(o){const i=o.get(e);if(i&&i.n===t)return i.g;o.set(e,{n:t,g:!1})}let s=null;try{for(const i of n.h||[])if(s=Reflect.has(e,i)!==Reflect.has(t,i),s)return s;if(n[Us]===!0){if(s=((i,l)=>{const c=Reflect.ownKeys(i),u=Reflect.ownKeys(l);return c.length!==u.length||c.some((d,m)=>d!==u[m])})(e,t),s)return s}else for(const i of n.o||[])if(s=!!Reflect.getOwnPropertyDescriptor(e,i)!=!!Reflect.getOwnPropertyDescriptor(t,i),s)return s;for(const i of n.k||[])if(s=px(e[i],t[i],r,o),s)return s;return s===null&&(s=!0),s}finally{o&&o.set(e,{n:t,g:s})}},s3=e=>!!uc(e)&&ux in e,fx=e=>uc(e)&&e[cc]||null,i3="h",a3="w",l3="o",c3="k",Cl=e=>typeof e=="object"&&e!==null,xx=(e,t)=>{if(!Cl(e))return e;const r=fx(e);return r!==null?(s3(e),r):(t.has(e)||(t.add(e),Object.entries(e).forEach(([o,n])=>{const s=xx(n,t);Object.is(s,n)||(e[o]=s)})),e)},$l=(e,t,r)=>{var o,n,s;if(!Cl(e)||!Cl(t))return;const i=r.get(fx(t)||t);i&&((o=i[i3])==null||o.forEach(l=>{Reflect.has(e,l)}),i[a3]===!0&&Reflect.ownKeys(e),(n=i[l3])==null||n.forEach(l=>{Reflect.getOwnPropertyDescriptor(e,l)}),(s=i[c3])==null||s.forEach(l=>{$l(e[l],t[l],r)}))},sl="o",il="r",al="a";function u3(e,t){var r;let o=0;const n=(r=t?.size)!=null?r:1,s=[],i=t!=null&&t.noWeakMap?null:new WeakMap;return c=>{const u=i?.get(c);if(u)return u[il];for(let h=0;h<n;h+=1){const y=s[(o+h)%n];if(!y)break;if(!px(y[sl],c,y[al],new WeakMap))return $l(c,y[sl],y[al]),i?.set(c,y),y[il]}const d=new WeakMap,m=mx(c,d),p=xx(e(m),new Set);$l(c,c,d);const f={[sl]:c,[il]:p,[al]:d};return o=(o-1+n)%n,s[o]=f,i?.set(c,f),p}}const d3=(e,t)=>x.runtime.RUNTIME==="browser"?u3(e,t):e,Io=(e,t)=>{v.useEffect(()=>{const r=new AbortController,o=r.signal,s=(async()=>(await x.scheduler.flushTaskQueue(),await e(o)))().catch(console.error);return()=>{r.abort(),s.then(i=>i?.()).catch(console.error)}},t)},m3=Object.freeze(Object.defineProperty({__proto__:null,Access:b.Access,Acquire:b.Acquire,Add:b.Add,Align:b.Align,Analyze:b.Analyze,Annotate:b.Annotate,Annotation:b.Annotation,Arc:b.Arc,Array:b.Array,Arrow:b.Arrow,Attachment:b.Attachment,Auto:b.Auto,AutoFitWidth:b.AutoFitWidth,Binary:b.Binary,Bolt:b.Bolt,Boolean:b.Boolean,Box:b.Box,Bridge:b.Bridge,CPlusPlus:b.CPlusPlus,CSV:b.CSV,Calculation:b.Calculation,Calendar:b.Calendar,Caret:b.Caret,Channel:b.Channel,Check:b.Check,Circle:b.Circle,Click:b.Click,Close:b.Close,Cluster:b.Cluster,Collapse:b.Collapse,Commit:b.Commit,Completed:b.Completed,Concepts:b.Concepts,Connect:b.Connect,Constant:b.Constant,Control:b.Control,Copy:b.Copy,Cut:b.Cut,DarkMode:b.DarkMode,Dashboard:b.Dashboard,Decimal:b.Decimal,Delete:b.Delete,Details:b.Details,Device:b.Device,Disable:b.Disable,Disconnect:b.Disconnect,Distribute:b.Distribute,Download:b.Download,Downsample:b.Downsample,Drag:b.Drag,Dynamic:b.Dynamic,Edit:b.Edit,EditOff:b.EditOff,Enable:b.Enable,Err:b.Err,Expand:b.Expand,Explore:b.Explore,Export:b.Export,False:b.False,Feedback:b.Feedback,FillColor:b.FillColor,Filter:b.Filter,Fitting:b.Fitting,Focus:b.Focus,Function:b.Function,Group:b.Group,Guide:b.Guide,Hardware:b.Hardware,Heart:b.Heart,Hidden:b.Hidden,Import:b.Import,InProgress:b.InProgress,Index:b.Index,Info:b.Info,JSON:b.JSON,KebabMenu:b.KebabMenu,Keyboard:b.Keyboard,Label:b.Label,LightMode:b.LightMode,LinePlot:b.LinePlot,Linear:b.Linear,Link:b.Link,LinkExternal:b.LinkExternal,Loading:b.Loading,Log:b.Log,Logo:b.Logo,Logout:b.Logout,Map:b.Map,Menu:b.Menu,MoveToMainWindow:b.MoveToMainWindow,NPM:b.NPM,Node:b.Node,None:b.None,Notification:b.Notification,OpenExternal:b.OpenExternal,OpenInNewWindow:b.OpenInNewWindow,PNPM:b.PNPM,Pan:b.Pan,Paste:b.Paste,Pause:b.Pause,Play:b.Play,Policy:b.Policy,Process:b.Process,Pump:b.Pump,Python:b.Python,QuestionMark:b.QuestionMark,Rack:b.Rack,Range:b.Range,Reference:b.Reference,Refresh:b.Refresh,Release:b.Release,Rename:b.Rename,Reset:b.Reset,Resources:b.Resources,Role:b.Role,Rotate:b.Rotate,RotateAroundCenter:b.RotateAroundCenter,RotateGroup:b.RotateGroup,Rule:b.Rule,Safety:b.Safety,Save:b.Save,Schematic:b.Schematic,Search:b.Search,Select:b.Select,Selection:b.Selection,Settings:b.Settings,Snapshot:b.Snapshot,Snooze:b.Snooze,Sound:b.Sound,SplitX:b.SplitX,SplitY:b.SplitY,StarFilled:b.StarFilled,StarOutlined:b.StarOutlined,Status:b.Status,String:b.String,StrokeColor:b.StrokeColor,StrokeWidth:b.StrokeWidth,Subtract:b.Subtract,Sync:b.Sync,Table:b.Table,Tank:b.Tank,Tare:b.Tare,Task:b.Task,Terminal:b.Terminal,Text:b.Text$1,TextAlign:b.TextAlign,Time:b.Time,ToDo:b.ToDo,Tooltip:b.Tooltip,True:b.True,Type:b.Type,TypeScript:b.TypeScript,Units:b.Units,User:b.User,Value:b.Value,Valve:b.Valve,Variable:b.Variable,View:b.View,Virtual:b.Virtual,Visible:b.Visible,Visualize:b.Visualize,Warning:b.Warning,Wave:b.Wave,Workspace:b.Workspace,Yarn:b.Yarn,Zoom:b.Zoom,createComposite:b.createComposite,resolve:b.resolve,wrapSVGIcon:b.wrapSVGIcon},Symbol.toStringTag,{value:"Module"})),p3=le.useVirtualCursorDragWebKit,bi=()=>{const e=v.useRef([]),t=v.useMemo(()=>({cleanup:()=>{e.current.forEach(r=>r()),e.current=[]},set:r=>{r!=null&&e.current.push(...x.array.toArray(r))}}),[]);return v.useEffect(()=>t.cleanup,[t.cleanup]),t},dc={info:"var(--pluto-text-color)",error:"var(--pluto-error-z)",warning:"var(--pluto-warning-m1)",success:"var(--pluto-primary-z)",loading:"var(--pluto-text-color)",disabled:"var(--pluto-gray-l8)"},wn=({variant:e,...t})=>e==="loading"?a.jsxRuntimeExports.jsx(b.Loading,{...t}):a.jsxRuntimeExports.jsx(b.Circle,{color:e!=null?dc[e]:void 0,...t}),f3=Object.freeze(Object.defineProperty({__proto__:null,Config:je.Config,Dialog:je.Dialog,chooseLocation:je.chooseLocation,formatTip:je.formatTip,useConfig:je.useConfig,wrap:je.wrap},Symbol.toStringTag,{value:"Module"})),x3=(e,t)=>{const r=new x.TimeRange(e).makeValid();if(r.start.equals(x.TimeStamp.MAX))return null;const o=r.start.isToday?"time":"dateTime";let n=new x.TimeStamp(r.start).toString(o,t);if(r.start.isToday&&(n=`Today ${n}`),r.end.equals(x.TimeStamp.MAX))return r.start.before(x.TimeStamp.now())?`Started ${n}`:`Starts ${n}`;const s=r.end.span(r.start)<x.TimeSpan.DAY?"time":"dateTime",i=new x.TimeStamp(r.end).toString(s,t);return[n,i]},hx=({children:e,level:t="p",color:r=9,displayTZ:o="local",weight:n=450,...s})=>{const i=x3(e,o);return i==null?null:a.jsxRuntimeExports.jsx(J.Box$1,{x:!0,gap:"small",align:"center",...s,children:a.jsxRuntimeExports.jsx(X.Text,{level:t,color:r,weight:n,gap:"tiny",children:typeof i=="string"?i:a.jsxRuntimeExports.jsxs(a.jsxRuntimeExports.Fragment,{children:[i[0],a.jsxRuntimeExports.jsx(b.Arrow.Right,{color:9,size:"1em"}),i[1]]})})})},gx=({children:e,format:t,...r})=>a.jsxRuntimeExports.jsx(X.Text,{...r,children:new x.TimeSpan(e).toString(t)}),yx=e=>{const[,t]=v.useState(0);return v.useEffect(()=>{const r=setInterval(()=>{t(o=>o+1)},1e3);return()=>clearInterval(r)},[]),x.TimeStamp.since(e)},h3=({children:e,...t})=>{const r=yx(e);return a.jsxRuntimeExports.jsx(gx,{...t,children:r})},g3=Object.freeze(Object.defineProperty({__proto__:null,TimeRange:hx,TimeSpan:gx,TimeSpanSince:h3,TimeStamp:ke.TimeStamp,useTimeSpanSince:yx},Symbol.toStringTag,{value:"Module"})),y3=({action:e})=>v.isValidElement(e)?e:v.createElement(je.Button,{...e,key:e.key,size:"tiny"}),v3=({status:{key:e,time:t,count:r,message:o,description:n,variant:s,name:i},silence:l,actions:c,className:u,children:d,...m})=>{const p=v.useRef(null);return a.jsxRuntimeExports.jsxs(J.Box$1,{className:g.CSS(g.CSS.B("notification"),u),y:!0,empty:!0,ref:p,...m,children:[a.jsxRuntimeExports.jsxs(J.Box$1,{x:!0,justify:"between",grow:!0,className:g.CSS(g.CSS.BE("notification","header")),children:[a.jsxRuntimeExports.jsxs(J.Box$1,{x:!0,align:"center",gap:"small",children:[a.jsxRuntimeExports.jsxs(X.Text,{level:"small",status:s,gap:"tiny",className:g.CSS(g.CSS.BE("notification","name")),children:[a.jsxRuntimeExports.jsx(wn,{variant:s}),a.jsxRuntimeExports.jsx(X.Text,{el:"span",overflow:"ellipsis",status:s,children:x.primitive.isNonZero(i)&&i})]}),a.jsxRuntimeExports.jsx(X.Text,{level:"small",children:`x${r}`}),a.jsxRuntimeExports.jsx(ke.TimeStamp,{className:g.CSS(g.CSS.BE("notification","time")),level:"small",format:"time",children:t})]}),a.jsxRuntimeExports.jsx(je.Button,{className:g.CSS(g.CSS.BE("notification","silence")),variant:"outlined",size:"small",onClick:()=>l(e),children:a.jsxRuntimeExports.jsx(b.Close,{})})]}),a.jsxRuntimeExports.jsxs(J.Box$1,{y:!0,align:"start",className:g.CSS(g.CSS.BE("notification","content")),gap:"small",children:[d??a.jsxRuntimeExports.jsx(X.Text,{className:g.CSS(g.CSS.BE("notification","message")),lineClamp:3,grow:!0,children:o}),n!=null&&a.jsxRuntimeExports.jsx(X.Text,{className:g.CSS(g.CSS.BE("notification","description")),level:"small",lineClamp:8,grow:!0,children:n})]}),c!=null&&a.jsxRuntimeExports.jsx(J.Box$1,{x:!0,align:"center",justify:"end",className:g.CSS(g.CSS.BE("notification","actions")),children:x.array.toArray(c).map(f=>a.jsxRuntimeExports.jsx(y3,{action:f},f.key))})]},t.toString())},co={...T.ZERO_CONTEXT_VALUE,state:R.Synnax.connectivity.DEFAULT},j3={maxRetries:4,baseInterval:R.TimeSpan.seconds(1),scale:2},[vx,jx]=b.create({defaultValue:co,displayName:"Synnax.Context"}),Vr=()=>jx().client,S3=()=>jx().state,Il={connected:"success",connecting:"loading",disconnected:"disabled",failed:"error"},Sx="serverVersionMismatch",E3=ce.object({type:ce.string(),oldServer:ce.boolean(),nodeVersion:ce.string().optional(),clientVersion:ce.string()}),b3=(e,t,r)=>`Core version ${r!=null?`${r} `:""}is ${e?"older":"newer"} than client version ${t}. Compatibility issues may arise.`,R3=({children:e,client:t})=>{const{path:r}=le.useUnidirectional({type:T.Provider.TYPE,schema:T.Provider.stateZ,state:{props:null,state:null}}),o=v.useMemo(()=>({...co,client:t}),[t]);return a.jsxRuntimeExports.jsx(vx,{value:o,children:a.jsxRuntimeExports.jsx(le.Composite,{path:r,children:e})})},Ex=({children:e,connParams:t})=>{const[r,o,n]=X.useCombinedStateAndRef(co),{path:s}=le.useUnidirectional({type:T.Provider.TYPE,schema:T.Provider.stateZ,state:{props:t??null,state:null}}),i=pe.useAdder(),l=v.useCallback(c=>{n.current.state.status!==c.status&&i({variant:Il[c.status],message:c.message??x.caseconv.capitalize(c.status)}),o(u=>({...u,state:c}))},[i]);return Io(async c=>{if(r.client!=null&&r.client.close(),t==null)return o(co);const u=new R.Synnax({retry:j3,...t,connectivityPollFrequency:R.TimeSpan.seconds(2)});o({client:u,state:{clusterKey:"",status:"connecting",message:"Connecting...",clientServerCompatible:!1,clientVersion:u.clientVersion}});const d=await u.connectivity.check();if(!c.aborted){if(o({client:u,state:d}),i({variant:Il[d.status],message:d.message??d.status.toUpperCase()}),d.status==="connected"&&!d.clientServerCompatible){const m=d.nodeVersion==null||x.migrate.semVerOlder(d.nodeVersion,d.clientVersion),p=b3(m,d.clientVersion,d.nodeVersion);i({variant:"warning",message:"Incompatible Core version",description:p,details:{type:Sx,oldServer:m,nodeVersion:d.nodeVersion,clientVersion:d.clientVersion}})}return u.connectivity.onChange(l),()=>{u.close(),o(co)}}},[t,l]),a.jsxRuntimeExports.jsx(vx,{value:r,children:a.jsxRuntimeExports.jsx(le.Composite,{path:s,children:e})})},_3=Object.freeze(Object.defineProperty({__proto__:null,CONNECTION_STATE_VARIANTS:Il,Provider:Ex,SERVER_VERSION_MISMATCH:Sx,TestProvider:R3,statusDetailsSchema:E3,use:Vr,useConnectionState:S3},Symbol.toStringTag,{value:"Module"})),[w3,k3]=b.create({displayName:"Flux.Context",providerName:"Flux.Provider"}),yt=e=>{const t=k3("Flux.useStore"),r=le.useUniqueKey(e);return v.useMemo(()=>t.scopedStore(r),[t,r])},bx=({children:e,...t})=>{const r=Vr(),o=pe.useErrorHandler(),n=pe.useAsyncErrorHandler(),{path:s}=le.useLifecycle({type:T.PROVIDER_TYPE,schema:T.providerStateZ,initialState:{}}),i=()=>"client"in t?t.client:new T.Client({client:r,storeConfig:t.storeConfig,handleError:o,handleAsyncError:n}),l=X.useInitializerRef(i),c=v.useRef(null);return r?.key!==c.current?.key&&(c.current=r,l.current=i()),a.jsxRuntimeExports.jsx(le.Composite,{path:s,children:a.jsxRuntimeExports.jsx(w3,{value:l.current,children:e})})},Rx=e=>{if("initialStatusDetails"in e)return e.initialStatusDetails},Fs=e=>{if("details"in e.status)return e.status.details},fn=((e,t,r)=>({variant:"loading",status:x.status.create({variant:"loading",message:`${x.caseconv.capitalize(e)}`,details:r}),data:t})),Rt=((e,t,r)=>({variant:"success",status:x.status.create({variant:"success",message:`Successfully ${e}`,details:r}),data:t})),Yn=(e,t)=>({variant:"error",status:x.status.fromException(t,`Failed to ${e}`),data:void 0}),_r=((e,t)=>({variant:"disabled",status:x.status.create({variant:"disabled",message:`Failed to ${e}`,description:`Cannot ${e} because no Core is connected.`,details:t}),data:void 0})),[_x,C3]=b.create({defaultValue:null,displayName:"Form.Context"}),gn=(e,t="Form.useContext")=>{const r=C3();if(r==null&&e==null)throw new Error(`${t} must be used within a Form context value`);return e??r},Qt=((e,t={})=>{const{optional:r=!1,onChange:o,defaultValue:n}=t,s=gn(t?.ctx,`useField(${e})`),{get:i,bind:l,set:c,setStatus:u}=s,d=v.useCallback(h=>{o?.(h,{...s,path:e}),c(e,h)},[e,c,o]),m=v.useCallback(h=>u(e,h),[e,u]),p=v.useSyncExternalStore(l,v.useCallback(()=>i(e,{optional:r,defaultValue:n}),[e,i,r,n]),()=>null);if(p==null){if(!r)throw new Error(`Field state is null: ${e}`);return null}const f=s.mode==="preview"?"preview":void 0;return{onChange:d,setStatus:m,variant:f,...p}}),mc=((e,t)=>{const{get:r,bind:o}=gn(t?.ctx);return v.useSyncExternalStore(o,v.useCallback(()=>r(e,t),[e,r,t]),()=>null)}),$n=((e,t)=>mc(e,t)?.value??null),$3=e=>mc(e,{optional:!0})?.status?.variant==="success",pc=(e,t)=>({value:()=>e.get(t).value,add:(r,o)=>{const n=x.shallow.copy(e.get(t).value);n.splice(o,0,...x.array.toArray(r)),e.set(t,n)},push:(r,o)=>{const n=x.shallow.copy(e.get(t).value);n.push(...x.array.toArray(r)),o!=null&&n.sort(o),e.set(t,n)},remove:r=>{const o=e.get(t).value,n=new Set(x.array.toArray(r)),s=o.filter(({key:i})=>!n.has(i));return e.set(t,s),s.map(({key:i})=>i)},keepOnly:r=>{const o=e.get(t).value,n=new Set(x.array.toArray(r)),s=o.filter(({key:i})=>n.has(i));return e.set(t,s),s.map(({key:i})=>i)},set:r=>e.set(t,ye.executeSetter(r,e.get(t).value)),sort:r=>{const o=x.shallow.copy(e.get(t).value);o.sort(r),e.set(t,o)}}),I3=(e,t)=>pc(gn(t?.ctx),e),Ri=(e,t={})=>{const r=gn(t?.ctx),o=$n(e,t);return v.useMemo(()=>({data:o.map(({key:n})=>n),...pc(r,e)}),[o,r,e])},T3=()=>a.jsxRuntimeExports.jsx(b.Caret.Right,{className:g.CSS.BE("breadcrumb","separator")}),qn=({children:e,...t})=>a.jsxRuntimeExports.jsx(X.Text,{className:g.CSS.BE("breadcrumb","segment"),...t,defaultEl:"span",children:e}),_i=({children:e,highlightVariant:t,...r})=>a.jsxRuntimeExports.jsx(X.Text,{className:g.CSS(g.CSS.B("breadcrumb"),t!=null&&g.CSS.BM("breadcrumb","highlight",t)),x:!0,align:"center",gap:"small",...r,children:v.Children.map(e,(o,n)=>o==null||typeof o=="boolean"?null:a.jsxRuntimeExports.jsxs(v.Fragment,{children:[n>0&&a.jsxRuntimeExports.jsx(T3,{}),typeof o=="string"?a.jsxRuntimeExports.jsx(qn,{children:o}):o]},n))}),P3=(e,t)=>{const r=e.split("/");return r.map((o,n)=>t({href:r.slice(0,n+1).join("/"),segment:o,index:n}))},N3=Object.freeze(Object.defineProperty({__proto__:null,Breadcrumb:_i,Segment:qn,mapURLSegments:P3},Symbol.toStringTag,{value:"Module"})),wx=({error:e,componentStack:t,resetErrorBoundary:r,children:o=a.jsxRuntimeExports.jsx(O3,{resetErrorBoundary:r}),extraInfo:n})=>{const s=v.useCallback(()=>{const i=[];return i.push(`Error: ${e.name}`),i.push(`Message: ${e.message}`),e.stack&&i.push(`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const R=require("@synnaxlabs/client"),x=require("@synnaxlabs/x"),ce=require("zod"),T=require("./value-DJPQ1lb4.cjs"),v=require("react"),a=require("./jsx-runtime-nZSsnGb7.cjs"),le=require("./Provider-B1JpVCIg.cjs"),b=require("./Text-_KoMj9Wf.cjs"),X=require("./Editable-HUPqTaui.cjs"),ye=require("./types-DI2vtOGs.cjs"),g=require("./css-CloSmhZB.cjs"),J=require("./Box-CNUz5BsV.cjs"),pe=require("./Tags-BE6wPgNv.cjs"),je=require("./Copy-6Mur4EW2.cjs"),ke=require("./external-C0FbiHkb.cjs"),xt=require("./Items-806FU8Ig.cjs"),dt=require("./Animated-C4AcIYpH.cjs"),ox=require("react-dom"),Ze=require("./Haul-BShXYNxx.cjs"),As=require("./provider-DQkVj3tA.cjs"),_t=require("./external-DUYMFee8.cjs"),J4=require("./useStaticData-BTwIe0Il.cjs"),ic=require("./external-Bzko45Io.cjs"),sx=require("./Animated-BhCfNN8N.cjs"),nt=require("./external-BY9Nw2gP.cjs"),Ys=require("./eraser-rFMFKqsg.cjs"),Xt=require("./event-BxvV3arE.cjs"),Si=require("./external-CROdzUNR.cjs"),Er=require("./hooks-DmaLjPZJ.cjs"),ix=require("./external-ByPmlfc-.cjs"),Rm=require("./dimensions-CdFEW3oU.cjs"),Ei=require("./external-RARODBsH.cjs"),_m=require("./Menu-ZISpSd-o.cjs");;/* empty css */const po=require("./external-qZkew-g7.cjs"),ax=require("./units-Bu36uC6z.cjs"),Q4=require("./external-VtOg79_6.cjs"),Ge=require("./external-9dcu01v6.cjs");require("@synnaxlabs/alamos");const e3=require("./external-BwbypKCk.cjs"),t3=require("./external-DOHVmFq6.cjs"),n3=require("./Video-BryrVNlH.cjs"),lt={present:"rename",past:"renamed",participle:"renaming"},ot={present:"delete",past:"deleted",participle:"deleting"},ac={present:"update",past:"updated",participle:"updating"},Jt={present:"create",past:"created",participle:"creating"},lc={present:"snapshot",past:"snapshotted",participle:"snapshotting"},lx={present:"copy",past:"copied",participle:"copying"},cx={present:"set",past:"set",participle:"setting"},r3={present:"save",past:"saved",participle:"saving"},ux=Symbol(),cc=Symbol(),eo="a",Us="w";let o3=(e,t)=>new Proxy(e,t);const kl=Object.getPrototypeOf,wm=new WeakMap,uc=e=>e&&(wm.has(e)?wm.get(e):kl(e)===Object.prototype||kl(e)===Array.prototype),km=e=>typeof e=="object"&&e!==null,Cm=new WeakMap,dx=e=>e[cc]||e,mx=(e,t,r)=>{if(!uc(e))return e;const o=dx(e),n=(i=>Object.isFrozen(i)||Object.values(Object.getOwnPropertyDescriptors(i)).some(l=>!l.writable))(o);let s=r&&r.get(o);return s&&s[1].f===n||(s=((i,l)=>{const c={f:l};let u=!1;const d=(p,f)=>{if(!u){let h=c[eo].get(i);if(h||(h={},c[eo].set(i,h)),p===Us)h[Us]=!0;else{let y=h[p];y||(y=new Set,h[p]=y),y.add(f)}}},m={get:(p,f)=>f===cc?i:(d("k",f),mx(Reflect.get(p,f),c[eo],c.c)),has:(p,f)=>f===ux?(u=!0,c[eo].delete(i),!0):(d("h",f),Reflect.has(p,f)),getOwnPropertyDescriptor:(p,f)=>(d("o",f),Reflect.getOwnPropertyDescriptor(p,f)),ownKeys:p=>(d(Us),Reflect.ownKeys(p))};return l&&(m.set=m.deleteProperty=()=>!1),[m,c]})(o,n),s[1].p=o3(n?(i=>{let l=Cm.get(i);if(!l){if(Array.isArray(i))l=Array.from(i);else{const c=Object.getOwnPropertyDescriptors(i);Object.values(c).forEach(u=>{u.configurable=!0}),l=Object.create(kl(i),c)}Cm.set(i,l)}return l})(o):o,s[0]),r&&r.set(o,s)),s[1][eo]=t,s[1].c=r,s[1].p},px=(e,t,r,o)=>{if(Object.is(e,t))return!1;if(!km(e)||!km(t))return!0;const n=r.get(dx(e));if(!n)return!0;if(o){const i=o.get(e);if(i&&i.n===t)return i.g;o.set(e,{n:t,g:!1})}let s=null;try{for(const i of n.h||[])if(s=Reflect.has(e,i)!==Reflect.has(t,i),s)return s;if(n[Us]===!0){if(s=((i,l)=>{const c=Reflect.ownKeys(i),u=Reflect.ownKeys(l);return c.length!==u.length||c.some((d,m)=>d!==u[m])})(e,t),s)return s}else for(const i of n.o||[])if(s=!!Reflect.getOwnPropertyDescriptor(e,i)!=!!Reflect.getOwnPropertyDescriptor(t,i),s)return s;for(const i of n.k||[])if(s=px(e[i],t[i],r,o),s)return s;return s===null&&(s=!0),s}finally{o&&o.set(e,{n:t,g:s})}},s3=e=>!!uc(e)&&ux in e,fx=e=>uc(e)&&e[cc]||null,i3="h",a3="w",l3="o",c3="k",Cl=e=>typeof e=="object"&&e!==null,xx=(e,t)=>{if(!Cl(e))return e;const r=fx(e);return r!==null?(s3(e),r):(t.has(e)||(t.add(e),Object.entries(e).forEach(([o,n])=>{const s=xx(n,t);Object.is(s,n)||(e[o]=s)})),e)},$l=(e,t,r)=>{var o,n,s;if(!Cl(e)||!Cl(t))return;const i=r.get(fx(t)||t);i&&((o=i[i3])==null||o.forEach(l=>{Reflect.has(e,l)}),i[a3]===!0&&Reflect.ownKeys(e),(n=i[l3])==null||n.forEach(l=>{Reflect.getOwnPropertyDescriptor(e,l)}),(s=i[c3])==null||s.forEach(l=>{$l(e[l],t[l],r)}))},sl="o",il="r",al="a";function u3(e,t){var r;let o=0;const n=(r=t?.size)!=null?r:1,s=[],i=t!=null&&t.noWeakMap?null:new WeakMap;return c=>{const u=i?.get(c);if(u)return u[il];for(let h=0;h<n;h+=1){const y=s[(o+h)%n];if(!y)break;if(!px(y[sl],c,y[al],new WeakMap))return $l(c,y[sl],y[al]),i?.set(c,y),y[il]}const d=new WeakMap,m=mx(c,d),p=xx(e(m),new Set);$l(c,c,d);const f={[sl]:c,[il]:p,[al]:d};return o=(o-1+n)%n,s[o]=f,i?.set(c,f),p}}const d3=(e,t)=>x.runtime.RUNTIME==="browser"?u3(e,t):e,Io=(e,t)=>{v.useEffect(()=>{const r=new AbortController,o=r.signal,s=(async()=>(await x.scheduler.flushTaskQueue(),await e(o)))().catch(console.error);return()=>{r.abort(),s.then(i=>i?.()).catch(console.error)}},t)},m3=Object.freeze(Object.defineProperty({__proto__:null,Access:b.Access,Acquire:b.Acquire,Add:b.Add,Align:b.Align,Analyze:b.Analyze,Annotate:b.Annotate,Annotation:b.Annotation,Arc:b.Arc,Array:b.Array,Arrow:b.Arrow,Attachment:b.Attachment,Auto:b.Auto,AutoFitWidth:b.AutoFitWidth,Binary:b.Binary,Bolt:b.Bolt,Boolean:b.Boolean,Box:b.Box,Bridge:b.Bridge,CPlusPlus:b.CPlusPlus,CSV:b.CSV,Calculation:b.Calculation,Calendar:b.Calendar,Caret:b.Caret,Channel:b.Channel,Check:b.Check,Circle:b.Circle,Click:b.Click,Close:b.Close,Cluster:b.Cluster,Collapse:b.Collapse,Commit:b.Commit,Completed:b.Completed,Concepts:b.Concepts,Connect:b.Connect,Constant:b.Constant,Control:b.Control,Copy:b.Copy,Cut:b.Cut,DarkMode:b.DarkMode,Dashboard:b.Dashboard,Decimal:b.Decimal,Delete:b.Delete,Details:b.Details,Device:b.Device,Disable:b.Disable,Disconnect:b.Disconnect,Distribute:b.Distribute,Download:b.Download,Downsample:b.Downsample,Drag:b.Drag,Dynamic:b.Dynamic,Edit:b.Edit,EditOff:b.EditOff,Enable:b.Enable,Err:b.Err,Expand:b.Expand,Explore:b.Explore,Export:b.Export,False:b.False,Feedback:b.Feedback,FillColor:b.FillColor,Filter:b.Filter,Fitting:b.Fitting,Focus:b.Focus,Function:b.Function,Group:b.Group,Guide:b.Guide,Hardware:b.Hardware,Heart:b.Heart,Hidden:b.Hidden,Import:b.Import,InProgress:b.InProgress,Index:b.Index,Info:b.Info,JSON:b.JSON,KebabMenu:b.KebabMenu,Keyboard:b.Keyboard,Label:b.Label,LightMode:b.LightMode,LinePlot:b.LinePlot,Linear:b.Linear,Link:b.Link,LinkExternal:b.LinkExternal,Loading:b.Loading,Log:b.Log,Logo:b.Logo,Logout:b.Logout,Map:b.Map,Menu:b.Menu,MoveToMainWindow:b.MoveToMainWindow,NPM:b.NPM,Node:b.Node,None:b.None,Notification:b.Notification,OpenExternal:b.OpenExternal,OpenInNewWindow:b.OpenInNewWindow,PNPM:b.PNPM,Pan:b.Pan,Paste:b.Paste,Pause:b.Pause,Play:b.Play,Policy:b.Policy,Process:b.Process,Pump:b.Pump,Python:b.Python,QuestionMark:b.QuestionMark,Rack:b.Rack,Range:b.Range,Reference:b.Reference,Refresh:b.Refresh,Release:b.Release,Rename:b.Rename,Reset:b.Reset,Resources:b.Resources,Role:b.Role,Rotate:b.Rotate,RotateAroundCenter:b.RotateAroundCenter,RotateGroup:b.RotateGroup,Rule:b.Rule,Safety:b.Safety,Save:b.Save,Schematic:b.Schematic,Search:b.Search,Select:b.Select,Selection:b.Selection,Settings:b.Settings,Snapshot:b.Snapshot,Snooze:b.Snooze,Sound:b.Sound,SplitX:b.SplitX,SplitY:b.SplitY,StarFilled:b.StarFilled,StarOutlined:b.StarOutlined,Status:b.Status,String:b.String,StrokeColor:b.StrokeColor,StrokeWidth:b.StrokeWidth,Subtract:b.Subtract,Sync:b.Sync,Table:b.Table,Tank:b.Tank,Tare:b.Tare,Task:b.Task,Terminal:b.Terminal,Text:b.Text$1,TextAlign:b.TextAlign,Time:b.Time,ToDo:b.ToDo,Tooltip:b.Tooltip,True:b.True,Type:b.Type,TypeScript:b.TypeScript,Units:b.Units,User:b.User,Value:b.Value,Valve:b.Valve,Variable:b.Variable,View:b.View,Virtual:b.Virtual,Visible:b.Visible,Visualize:b.Visualize,Warning:b.Warning,Wave:b.Wave,Workspace:b.Workspace,Yarn:b.Yarn,Zoom:b.Zoom,createComposite:b.createComposite,resolve:b.resolve,wrapSVGIcon:b.wrapSVGIcon},Symbol.toStringTag,{value:"Module"})),p3=le.useVirtualCursorDragWebKit,bi=()=>{const e=v.useRef([]),t=v.useMemo(()=>({cleanup:()=>{e.current.forEach(r=>r()),e.current=[]},set:r=>{r!=null&&e.current.push(...x.array.toArray(r))}}),[]);return v.useEffect(()=>t.cleanup,[t.cleanup]),t},dc={info:"var(--pluto-text-color)",error:"var(--pluto-error-z)",warning:"var(--pluto-warning-m1)",success:"var(--pluto-primary-z)",loading:"var(--pluto-text-color)",disabled:"var(--pluto-gray-l8)"},wn=({variant:e,...t})=>e==="loading"?a.jsxRuntimeExports.jsx(b.Loading,{...t}):a.jsxRuntimeExports.jsx(b.Circle,{color:e!=null?dc[e]:void 0,...t}),f3=Object.freeze(Object.defineProperty({__proto__:null,Config:je.Config,Dialog:je.Dialog,chooseLocation:je.chooseLocation,formatTip:je.formatTip,useConfig:je.useConfig,wrap:je.wrap},Symbol.toStringTag,{value:"Module"})),x3=(e,t)=>{const r=new x.TimeRange(e).makeValid();if(r.start.equals(x.TimeStamp.MAX))return null;const o=r.start.isToday?"time":"dateTime";let n=new x.TimeStamp(r.start).toString(o,t);if(r.start.isToday&&(n=`Today ${n}`),r.end.equals(x.TimeStamp.MAX))return r.start.before(x.TimeStamp.now())?`Started ${n}`:`Starts ${n}`;const s=r.end.span(r.start)<x.TimeSpan.DAY?"time":"dateTime",i=new x.TimeStamp(r.end).toString(s,t);return[n,i]},hx=({children:e,level:t="p",color:r=9,displayTZ:o="local",weight:n=450,...s})=>{const i=x3(e,o);return i==null?null:a.jsxRuntimeExports.jsx(J.Box$1,{x:!0,gap:"small",align:"center",...s,children:a.jsxRuntimeExports.jsx(X.Text,{level:t,color:r,weight:n,gap:"tiny",children:typeof i=="string"?i:a.jsxRuntimeExports.jsxs(a.jsxRuntimeExports.Fragment,{children:[i[0],a.jsxRuntimeExports.jsx(b.Arrow.Right,{color:9,size:"1em"}),i[1]]})})})},gx=({children:e,format:t,...r})=>a.jsxRuntimeExports.jsx(X.Text,{...r,children:new x.TimeSpan(e).toString(t)}),yx=e=>{const[,t]=v.useState(0);return v.useEffect(()=>{const r=setInterval(()=>{t(o=>o+1)},1e3);return()=>clearInterval(r)},[]),x.TimeStamp.since(e)},h3=({children:e,...t})=>{const r=yx(e);return a.jsxRuntimeExports.jsx(gx,{...t,children:r})},g3=Object.freeze(Object.defineProperty({__proto__:null,TimeRange:hx,TimeSpan:gx,TimeSpanSince:h3,TimeStamp:ke.TimeStamp,useTimeSpanSince:yx},Symbol.toStringTag,{value:"Module"})),y3=({action:e})=>v.isValidElement(e)?e:v.createElement(je.Button,{...e,key:e.key,size:"tiny"}),v3=({status:{key:e,time:t,count:r,message:o,description:n,variant:s,name:i},silence:l,actions:c,className:u,children:d,...m})=>{const p=v.useRef(null);return a.jsxRuntimeExports.jsxs(J.Box$1,{className:g.CSS(g.CSS.B("notification"),u),y:!0,empty:!0,ref:p,...m,children:[a.jsxRuntimeExports.jsxs(J.Box$1,{x:!0,justify:"between",grow:!0,className:g.CSS(g.CSS.BE("notification","header")),children:[a.jsxRuntimeExports.jsxs(J.Box$1,{x:!0,align:"center",gap:"small",children:[a.jsxRuntimeExports.jsxs(X.Text,{level:"small",status:s,gap:"tiny",className:g.CSS(g.CSS.BE("notification","name")),children:[a.jsxRuntimeExports.jsx(wn,{variant:s}),a.jsxRuntimeExports.jsx(X.Text,{el:"span",overflow:"ellipsis",status:s,children:x.primitive.isNonZero(i)&&i})]}),a.jsxRuntimeExports.jsx(X.Text,{level:"small",children:`x${r}`}),a.jsxRuntimeExports.jsx(ke.TimeStamp,{className:g.CSS(g.CSS.BE("notification","time")),level:"small",format:"time",children:t})]}),a.jsxRuntimeExports.jsx(je.Button,{className:g.CSS(g.CSS.BE("notification","silence")),variant:"outlined",size:"small",onClick:()=>l(e),children:a.jsxRuntimeExports.jsx(b.Close,{})})]}),a.jsxRuntimeExports.jsxs(J.Box$1,{y:!0,align:"start",className:g.CSS(g.CSS.BE("notification","content")),gap:"small",children:[d??a.jsxRuntimeExports.jsx(X.Text,{className:g.CSS(g.CSS.BE("notification","message")),lineClamp:3,grow:!0,children:o}),n!=null&&a.jsxRuntimeExports.jsx(X.Text,{className:g.CSS(g.CSS.BE("notification","description")),level:"small",lineClamp:8,grow:!0,children:n})]}),c!=null&&a.jsxRuntimeExports.jsx(J.Box$1,{x:!0,align:"center",justify:"end",className:g.CSS(g.CSS.BE("notification","actions")),children:x.array.toArray(c).map(f=>a.jsxRuntimeExports.jsx(y3,{action:f},f.key))})]},t.toString())},co={...T.ZERO_CONTEXT_VALUE,state:R.Synnax.connectivity.DEFAULT},j3={maxRetries:4,baseInterval:R.TimeSpan.seconds(1),scale:2},[vx,jx]=b.create({defaultValue:co,displayName:"Synnax.Context"}),Vr=()=>jx().client,S3=()=>jx().state,Il={connected:"success",connecting:"loading",disconnected:"disabled",failed:"error"},Sx="serverVersionMismatch",E3=ce.object({type:ce.string(),oldServer:ce.boolean(),nodeVersion:ce.string().optional(),clientVersion:ce.string()}),b3=(e,t,r)=>`Core version ${r!=null?`${r} `:""}is ${e?"older":"newer"} than client version ${t}. Compatibility issues may arise.`,R3=({children:e,client:t})=>{const{path:r}=le.useUnidirectional({type:T.Provider.TYPE,schema:T.Provider.stateZ,state:{props:null,state:null}}),o=v.useMemo(()=>({...co,client:t}),[t]);return a.jsxRuntimeExports.jsx(vx,{value:o,children:a.jsxRuntimeExports.jsx(le.Composite,{path:r,children:e})})},Ex=({children:e,connParams:t})=>{const[r,o,n]=X.useCombinedStateAndRef(co),{path:s}=le.useUnidirectional({type:T.Provider.TYPE,schema:T.Provider.stateZ,state:{props:t??null,state:null}}),i=pe.useAdder(),l=v.useCallback(c=>{n.current.state.status!==c.status&&i({variant:Il[c.status],message:c.message??x.caseconv.capitalize(c.status)}),o(u=>({...u,state:c}))},[i]);return Io(async c=>{if(r.client!=null&&r.client.close(),t==null)return o(co);const u=new R.Synnax({retry:j3,...t,connectivityPollFrequency:R.TimeSpan.seconds(2)});o({client:u,state:{clusterKey:"",status:"connecting",message:"Connecting...",clientServerCompatible:!1,clientVersion:u.clientVersion}});const d=await u.connectivity.check();if(!c.aborted){if(o({client:u,state:d}),i({variant:Il[d.status],message:d.message??d.status.toUpperCase()}),d.status==="connected"&&!d.clientServerCompatible){const m=d.nodeVersion==null||x.migrate.semVerOlder(d.nodeVersion,d.clientVersion),p=b3(m,d.clientVersion,d.nodeVersion);i({variant:"warning",message:"Incompatible Core version",description:p,details:{type:Sx,oldServer:m,nodeVersion:d.nodeVersion,clientVersion:d.clientVersion}})}return u.connectivity.onChange(l),()=>{u.close(),o(co)}}},[t,l]),a.jsxRuntimeExports.jsx(vx,{value:r,children:a.jsxRuntimeExports.jsx(le.Composite,{path:s,children:e})})},_3=Object.freeze(Object.defineProperty({__proto__:null,CONNECTION_STATE_VARIANTS:Il,Provider:Ex,SERVER_VERSION_MISMATCH:Sx,TestProvider:R3,statusDetailsSchema:E3,use:Vr,useConnectionState:S3},Symbol.toStringTag,{value:"Module"})),[w3,k3]=b.create({displayName:"Flux.Context",providerName:"Flux.Provider"}),yt=e=>{const t=k3("Flux.useStore"),r=le.useUniqueKey(e);return v.useMemo(()=>t.scopedStore(r),[t,r])},bx=({children:e,...t})=>{const r=Vr(),o=pe.useErrorHandler(),n=pe.useAsyncErrorHandler(),{path:s}=le.useLifecycle({type:T.PROVIDER_TYPE,schema:T.providerStateZ,initialState:{}}),i=()=>"client"in t?t.client:new T.Client({client:r,storeConfig:t.storeConfig,handleError:o,handleAsyncError:n}),l=X.useInitializerRef(i),c=v.useRef(null);return r?.key!==c.current?.key&&(c.current=r,l.current=i()),a.jsxRuntimeExports.jsx(le.Composite,{path:s,children:a.jsxRuntimeExports.jsx(w3,{value:l.current,children:e})})},Rx=e=>{if("initialStatusDetails"in e)return e.initialStatusDetails},Fs=e=>{if("details"in e.status)return e.status.details},fn=((e,t,r)=>({variant:"loading",status:x.status.create({variant:"loading",message:`${x.caseconv.capitalize(e)}`,details:r}),data:t})),Rt=((e,t,r)=>({variant:"success",status:x.status.create({variant:"success",message:`Successfully ${e}`,details:r}),data:t})),Yn=(e,t)=>({variant:"error",status:x.status.fromException(t,`Failed to ${e}`),data:void 0}),_r=((e,t)=>({variant:"disabled",status:x.status.create({variant:"disabled",message:`Failed to ${e}`,description:`Cannot ${e} because no Core is connected.`,details:t}),data:void 0})),[_x,C3]=b.create({defaultValue:null,displayName:"Form.Context"}),gn=(e,t="Form.useContext")=>{const r=C3();if(r==null&&e==null)throw new Error(`${t} must be used within a Form context value`);return e??r},Qt=((e,t={})=>{const{optional:r=!1,onChange:o,defaultValue:n}=t,s=gn(t?.ctx,`useField(${e})`),{get:i,bind:l,set:c,setStatus:u}=s,d=v.useCallback(h=>{o?.(h,{...s,path:e}),c(e,h)},[e,c,o]),m=v.useCallback(h=>u(e,h),[e,u]),p=v.useSyncExternalStore(l,v.useCallback(()=>i(e,{optional:r,defaultValue:n}),[e,i,r,n]),()=>null);if(p==null){if(!r)throw new Error(`Field state is null: ${e}`);return null}const f=s.mode==="preview"?"preview":void 0;return{onChange:d,setStatus:m,variant:f,...p}}),mc=((e,t)=>{const{get:r,bind:o}=gn(t?.ctx);return v.useSyncExternalStore(o,v.useCallback(()=>r(e,t),[e,r,t]),()=>null)}),$n=((e,t)=>mc(e,t)?.value??null),$3=e=>mc(e,{optional:!0})?.status?.variant==="success",pc=(e,t)=>({value:()=>e.get(t).value,add:(r,o)=>{const n=x.shallow.copy(e.get(t).value);n.splice(o,0,...x.array.toArray(r)),e.set(t,n)},push:(r,o)=>{const n=x.shallow.copy(e.get(t).value);n.push(...x.array.toArray(r)),o!=null&&n.sort(o),e.set(t,n)},remove:r=>{const o=e.get(t).value,n=new Set(x.array.toArray(r)),s=o.filter(({key:i})=>!n.has(i));return e.set(t,s),s.map(({key:i})=>i)},keepOnly:r=>{const o=e.get(t).value,n=new Set(x.array.toArray(r)),s=o.filter(({key:i})=>n.has(i));return e.set(t,s),s.map(({key:i})=>i)},set:r=>e.set(t,ye.executeSetter(r,e.get(t).value)),sort:r=>{const o=x.shallow.copy(e.get(t).value);o.sort(r),e.set(t,o)}}),I3=(e,t)=>pc(gn(t?.ctx),e),Ri=(e,t={})=>{const r=gn(t?.ctx),o=$n(e,t);return v.useMemo(()=>({data:o.map(({key:n})=>n),...pc(r,e)}),[o,r,e])},T3=()=>a.jsxRuntimeExports.jsx(b.Caret.Right,{className:g.CSS.BE("breadcrumb","separator")}),qn=({children:e,...t})=>a.jsxRuntimeExports.jsx(X.Text,{className:g.CSS.BE("breadcrumb","segment"),...t,defaultEl:"span",children:e}),_i=({children:e,highlightVariant:t,...r})=>a.jsxRuntimeExports.jsx(X.Text,{className:g.CSS(g.CSS.B("breadcrumb"),t!=null&&g.CSS.BM("breadcrumb","highlight",t)),x:!0,align:"center",gap:"small",...r,children:v.Children.map(e,(o,n)=>o==null||typeof o=="boolean"?null:a.jsxRuntimeExports.jsxs(v.Fragment,{children:[n>0&&a.jsxRuntimeExports.jsx(T3,{}),typeof o=="string"?a.jsxRuntimeExports.jsx(qn,{children:o}):o]},n))}),P3=(e,t)=>{const r=e.split("/");return r.map((o,n)=>t({href:r.slice(0,n+1).join("/"),segment:o,index:n}))},N3=Object.freeze(Object.defineProperty({__proto__:null,Breadcrumb:_i,Segment:qn,mapURLSegments:P3},Symbol.toStringTag,{value:"Module"})),wx=({error:e,componentStack:t,resetErrorBoundary:r,children:o=a.jsxRuntimeExports.jsx(O3,{resetErrorBoundary:r}),extraInfo:n})=>{const s=v.useCallback(()=>{const i=[];return i.push(`Error: ${e.name}`),i.push(`Message: ${e.message}`),e.stack&&i.push(`
2
2
  Stack Trace:
3
3
  ${e.stack}
4
4
  `),t&&i.push(`
package/dist/index.js CHANGED
@@ -2,8 +2,8 @@ import { Synnax as zy, TimeSpan as Ly, ontology as V, access as vt, user as br,
2
2
  import { runtime as bi, scheduler as cE, array as Me, TimeRange as qu, TimeStamp as Bt, TimeSpan as $n, primitive as Ue, caseconv as _r, migrate as uE, status as Vo, shallow as Fc, location as De, direction as He, box as B, math as dE, clamp as Zc, color as Y, unique as Uy, deep as ze, observe as fE, map as Gp, zod as mE, compare as Yp, uuid as Va, xy as le, record as Fy, dimensions as Lr, scale as kn, sticky as Bc, DataType as en, bounds as Zy, notation as pE, id as hE } from "@synnaxlabs/x";
3
3
  import { DataType as Gee, Density as Yee, MultiSeries as Wee, Rate as Xee, Series as qee, TimeRange as Jee, TimeSpan as Qee, TimeStamp as ete } from "@synnaxlabs/x";
4
4
  import Vt, { z as ye } from "zod";
5
- import { Z as gE, _ as ua, $ as yE, a0 as vE, a1 as By, a2 as xE, a3 as bE, a4 as Cn, a5 as _E, M as Vy, G as Hy, K as Ky, E as Gy, a6 as SE, a7 as Yy, a8 as Ir, a9 as Wp, aa as Xp, ab as wE, ac as Vc, ad as $E, ae as kE, af as jE, ag as EE, ah as CE, ai as IE, aj as NE, ak as TE, al as PE, am as OE, an as zE, ao as LE, ap as RE, l as DE, b as ME, L as AE, aq as As, ar as UE, as as FE, at as ZE, X as BE, Y as VE, au as HE, av as KE, aw as GE, ax as YE, ay as WE, az as XE, aA as qE, aB as JE, aC as QE, aD as eC, aE as qp, aF as Jp, aG as tC, aH as nC, aI as rC, aJ as oC, aK as iC, aL as sC, aM as Wy, aN as Xy, aO as qy, aP as Jy, z as aC, aQ as lC, aR as Qy, aS as Ho, aT as cC, aU as Ko, aV as uC, aW as dC, aX as ev, aY as fC, aZ as tv, a_ as nv, a$ as rv, b0 as mC, b1 as ov, b2 as tr, b3 as Go, b4 as iv, b5 as pC, b6 as hC, b7 as gC, b8 as yC, b9 as vC, ba as xC, bb as Ha, bc as Ka, bd as bC, be as _C, bf as Dn, bg as gi, bh as da, bi as jn, bj as pu, bk as Di, bl as SC, bm as fa, bn as Sr, bo as Ju, bp as hu, bq as wC, br as $C, bs as kC, bt as jC, bu as EC, bv as CC, bw as IC, bx as NC, by as TC, bz as PC, bA as OC, bB as zC, bC as LC, bD as sv, bE as av, bF as Qp, F as RC, D as DC, H as MC, I as AC, J as UC, N as FC, bG as ZC } from "./value-DimszMFu.js";
6
- import { U as nte } from "./value-DimszMFu.js";
5
+ import { Z as gE, _ as ua, $ as yE, a0 as vE, a1 as By, a2 as xE, a3 as bE, a4 as Cn, a5 as _E, M as Vy, G as Hy, K as Ky, E as Gy, a6 as SE, a7 as Yy, a8 as Ir, a9 as Wp, aa as Xp, ab as wE, ac as Vc, ad as $E, ae as kE, af as jE, ag as EE, ah as CE, ai as IE, aj as NE, ak as TE, al as PE, am as OE, an as zE, ao as LE, ap as RE, l as DE, b as ME, L as AE, aq as As, ar as UE, as as FE, at as ZE, X as BE, Y as VE, au as HE, av as KE, aw as GE, ax as YE, ay as WE, az as XE, aA as qE, aB as JE, aC as QE, aD as eC, aE as qp, aF as Jp, aG as tC, aH as nC, aI as rC, aJ as oC, aK as iC, aL as sC, aM as Wy, aN as Xy, aO as qy, aP as Jy, z as aC, aQ as lC, aR as Qy, aS as Ho, aT as cC, aU as Ko, aV as uC, aW as dC, aX as ev, aY as fC, aZ as tv, a_ as nv, a$ as rv, b0 as mC, b1 as ov, b2 as tr, b3 as Go, b4 as iv, b5 as pC, b6 as hC, b7 as gC, b8 as yC, b9 as vC, ba as xC, bb as Ha, bc as Ka, bd as bC, be as _C, bf as Dn, bg as gi, bh as da, bi as jn, bj as pu, bk as Di, bl as SC, bm as fa, bn as Sr, bo as Ju, bp as hu, bq as wC, br as $C, bs as kC, bt as jC, bu as EC, bv as CC, bw as IC, bx as NC, by as TC, bz as PC, bA as OC, bB as zC, bC as LC, bD as sv, bE as av, bF as Qp, F as RC, D as DC, H as MC, I as AC, J as UC, N as FC, bG as ZC } from "./value-CQ1JSZ3H.js";
6
+ import { U as nte } from "./value-CQ1JSZ3H.js";
7
7
  import Mi, { useEffect as ne, useRef as oe, useMemo as Ne, useState as Te, isValidElement as BC, createElement as Qu, useCallback as F, useSyncExternalStore as ed, Children as lv, Fragment as $o, Component as VC, memo as qe, createContext as td, useContext as Ai, forwardRef as cv, useLayoutEffect as uv, useImperativeHandle as dv, createRef as HC, cloneElement as KC } from "react";
8
8
  import { j as a } from "./jsx-runtime-tc70JA_2.js";
9
9
  import { d as GC, e as to, C as ln, f as nr, g as fv, c as ft, a as no, h as YC, i as WC, P as XC, j as qC } from "./Provider-CfgP1iWx.js";
@@ -5084,7 +5084,7 @@ class fn extends U {
5084
5084
  L = "Time", _ = l.toString("preciseDate", "local");
5085
5085
  else {
5086
5086
  const P = a[v - 1];
5087
- L = P.label ?? "", _ = $e.roundBySpan(P.value.y, P.bounds).toString(), O = P.color;
5087
+ L = P.label ?? "", _ = $e.smartRound(P.value.y, P.bounds).toString(), O = P.color;
5088
5088
  }
5089
5089
  o.text({
5090
5090
  position: p.topLeft(T),
@@ -5251,7 +5251,7 @@ class pn extends U {
5251
5251
  });
5252
5252
  }
5253
5253
  drawPointLabel(e) {
5254
- const { pointNumber: t, position: s, value: r, units: i, bounds: a, toTop: o, viewRegion: c, xDist: l } = e, { draw: h, theme: d } = this.internal, m = new I(r.x), b = m.toString(m.formatBySpan(l), "local"), w = `${$e.roundBySpan(r.y, a)} ${i ?? ""}`, v = `${t}`, T = v.length * dt, L = f.construct(ut), _ = dt, O = Math.max(b.length, w.length), P = T + Zr + _ + O * Zt + L.x * Bt, q = ht, S = q * 2 + L.y * 2;
5254
+ const { pointNumber: t, position: s, value: r, units: i, bounds: a, toTop: o, viewRegion: c, xDist: l } = e, { draw: h, theme: d } = this.internal, m = new I(r.x), b = m.toString(m.formatBySpan(l), "local"), w = `${$e.smartRound(r.y, a)} ${i ?? ""}`, v = `${t}`, T = v.length * dt, L = f.construct(ut), _ = dt, O = Math.max(b.length, w.length), P = T + Zr + _ + O * Zt + L.x * Bt, q = ht, S = q * 2 + L.y * 2;
5255
5255
  let D = o ? -(S + Ze) : Ze, Y = p.construct(
5256
5256
  f.translate(s, [-P / 2, D]),
5257
5257
  P,
@@ -5370,8 +5370,8 @@ class pn extends U {
5370
5370
  lineDash: a,
5371
5371
  lineWidth: o
5372
5372
  }), this.drawPointMarker(l, s.color), this.drawPointMarker(h, r.color);
5373
- const q = `${$e.roundBySpan(b, C.construct(b))} ${s.units ?? ""}`, S = w.lessThan(E.milliseconds(Wh)) ? E.MICROSECOND : E.MILLISECOND, D = w.truncate(S).toString();
5374
- let Y = $e.roundBySpan(v, C.construct(Math.abs(v))).toString();
5373
+ const q = `${$e.smartRound(b, C.construct(b))} ${s.units ?? ""}`, S = w.lessThan(E.milliseconds(Wh)) ? E.MICROSECOND : E.MILLISECOND, D = w.truncate(S).toString();
5374
+ let Y = $e.smartRound(v, C.construct(Math.abs(v))).toString();
5375
5375
  if (s.units != null && s.units.length > 0 && (Y += ` ${s.units} / s`), P) {
5376
5376
  const oe = f.construct(
5377
5377
  (l.x + h.x) / 2,
@@ -50,4 +50,4 @@ uniform mediump vec2 u_offset_aggregate;
50
50
  void main(void) {
51
51
  gl_Position = vec4((u_scale_aggregate * vec2(a_x, float(a_y)) + u_offset_aggregate) + a_translate, 0.0, 1.0);
52
52
  }
53
- `,jo=h.z.object({x:Mt,y:Mt,label:h.z.string().optional(),color:r.color.colorZ,strokeWidth:h.z.number().default(1),downsample:h.z.number().min(1).max(50).default(1),downsampleMode:Ns.default("decimate"),visible:h.z.boolean().default(!0)}),Ll=(n,e,t)=>n===-1||e===-1||n>=t.series.length?NaN:Number(t.series[n].at(e)),kl=r.TimeSpan.milliseconds(2);r.xy.NAN,r.xy.NAN,r.color.ZERO,r.bounds.ZERO;const _l=(n,e)=>e.equals(r.DataType.UINT8)?n.UNSIGNED_BYTE:n.FLOAT;class mr extends I.GLProgram{translationBufferCache=new Map;constructor(e,t,s){super(e,t,s),this.translationBufferCache=new Map}bindState({strokeWidth:e,color:t}){return this.uniformColor("u_color",t),this.attrStrokeWidth(e)}bindScale(e,t){const s=r.xy.scale(e.scale,t.scale),o=r.xy.translate(r.xy.scale(t.scale,e.offset),t.offset);this.uniformXY("u_scale_aggregate",s),this.uniformXY("u_offset_aggregate",o)}draw({x:e,y:t,count:s,downsample:o,xOffset:i,yOffset:a},l,u,c){const{gl:d}=this.renderCtx;this.bindAttrBuffer("x",e.glBuffer,o,i,u),this.bindAttrBuffer("y",t.glBuffer,o,a,c),d.drawArraysInstanced(d.LINE_STRIP,0,s/o,l)}bindAttrBuffer(e,t,s,o=0,i){const{gl:a}=this.renderCtx;a.bindBuffer(a.ARRAY_BUFFER,t);const l=a.getAttribLocation(this.prog,`a_${e}`),u=_l(a,i),c=i.density.valueOf();i.equals(r.DataType.UINT8)?a.vertexAttribIPointer(l,1,u,c*s,c*o):a.vertexAttribPointer(l,1,u,!1,c*s,c*o),a.enableVertexAttribArray(l)}getAndBindTranslationBuffer(e){const{gl:t}=this.renderCtx,s=`${this.renderCtx.aspect}:${e}`,o=this.translationBufferCache.get(s);if(o!=null)return t.bindBuffer(t.ARRAY_BUFFER,o.glBuffer),o;const i=t.createBuffer();if(i==null)throw new x.UnexpectedError("Failed to create buffer from WebGL context");const a=Ml(this.renderCtx.aspect,e);t.bindBuffer(t.ARRAY_BUFFER,i),t.bufferData(t.ARRAY_BUFFER,a,t.DYNAMIC_DRAW);const l={glBuffer:i,jsBuffer:a};return this.translationBufferCache.set(s,l),l}attrStrokeWidth(e){const{gl:t}=this.renderCtx,{jsBuffer:s}=this.getAndBindTranslationBuffer(e),o=t.getAttribLocation(this.prog,"a_translate");return t.vertexAttribPointer(o,2,t.FLOAT,!1,0,0),t.enableVertexAttribArray(o),t.vertexAttribDivisor(o,1),s.length/2}}class _e{static CONTEXT_KEY="pluto-line-gl-program";uint8HybridProgram;float32Program;constructor(e){this.uint8HybridProgram=new mr(e,Pl,pr),this.float32Program=new mr(e,Rl,pr)}get gl(){return this.uint8HybridProgram.renderCtx.gl}getProgram(e){return e.equals(r.DataType.UINT8)?this.uint8HybridProgram:this.float32Program}static create(e,t){const s=new _e(t);return e.set(_e.CONTEXT_KEY,s),s}static use(e){const t=e.get(_e.CONTEXT_KEY);if(t==null)throw new x.UnexpectedError("GLProgram not found");return t}}class $t extends w.Leaf{static TYPE="line";schema=jo;afterUpdate(e){const{internal:t}=this,s={onStatusChange:w.useAdder(e)};t.xTelem=U(e,this.state.x,t.xTelem,s),t.yTelem=U(e,this.state.y,t.yTelem,s),t.instrumentation=I.useInstrumentation(e,"line"),t.lineCtx=_e.use(e),t.requestRender=an(e),t.stopListeningXTelem?.(),t.stopListeningYTelem?.(),t.stopListeningXTelem=t.xTelem.onChange(()=>t.requestRender("data")),t.stopListeningYTelem=t.yTelem.onChange(()=>t.requestRender("data")),t.requestRender("layout"),(t.xDownsampler?.props.mode!==this.state.downsampleMode||t.xDownsampler?.props.windowSize!==this.state.downsample)&&(t.xDownsampler=new st({mode:this.state.downsampleMode,windowSize:this.state.downsample}),t.yDownsampler=new st({mode:this.state.downsampleMode,windowSize:this.state.downsample}))}afterDelete(){const{internal:e}=this;e.xTelem.cleanup?.(),e.yTelem.cleanup?.(),e.requestRender("layout")}xBounds(){return this.internal.xTelem.value()[0]}yBounds(){return this.internal.yTelem.value()[0]}findByXValue(e,t){const{xTelem:s,yTelem:o}=this.internal;let[,i]=s.value();i=this.internal.xDownsampler.transform(i);let[a,l]=[-1,-1];i.series.find((v,R)=>{const L=v.binarySearch(t),k=L>=0&&L<v.length;return k&&([a,l]=[L,R]),k});const{key:u}=this,{color:c,label:d}=this.state,f={key:u,color:c,label:d,position:{x:0,y:0},value:{x:NaN,y:NaN},bounds:{lower:0,upper:0}};if(a===-1||l===-1||!this.state.visible)return f;const p=i.series[l];f.value.x=Ll(l,a,i);let[,g]=o.value();g=this.internal.yDownsampler.transform(g);const T=g.series.find(v=>r.bounds.contains(v.alignmentBounds,p.alignment+BigInt(a)));if(T==null)return f;const y=Number(T.alignment-p.alignment);return f.value.y=Number(T.at(a-y)),f.bounds={...T.bounds},f.position={x:e.dataToDecimalScale.x.pos(f.value.x),y:e.dataToDecimalScale.y.pos(f.value.y)},f}render(e){if(this.deleted||!this.state.visible)return;const{downsample:t}=this.state,{xTelem:s,yTelem:o,lineCtx:i,xDownsampler:a,yDownsampler:l}=this.internal,{dataToDecimalScale:u,exposure:c}=e;let[[,d],[,f]]=[s.value(),o.value()];if(d=a.transform(d),f=l.transform(f),d.updateGLBuffer(i.gl),f.updateGLBuffer(i.gl),d.length===0||f.length===0)return;const p=i.getProgram(f.dataType),g=Nl(d,f,c,t,this.state.downsampleMode,kl);this.internal.instrumentation.L.debug("render",()=>({key:this.key,downsample:t,scale:u.transform,props:e.region,ops:Zl(g)}));const T=p.setAsActive(),y=p.bindState(this.state),v=p.renderCtx.scaleRegion(e.region).transform;g.forEach(R=>{const L=zl(u,R).transform;p.bindScale(L,v),p.draw(R,y,d.dataType,f.dataType)}),T()}}const Ol=5e3,Ml=(n,e)=>Il(Al(n),e).map((t,s)=>Math.floor(s/Dl)*(1/(Ol*n))*t),Dl=5,Al=n=>new Float32Array([0,0,0,n,0,-n,1,0,-1,0]),Il=(n,e)=>{const t=new Float32Array(n.length*e);for(let s=0;s<e;s++)t.set(n,s*n.length);return t},zl=(n,e)=>n.translate(n.x.dim(Number(e.x.sampleOffset)),n.y.dim(Number(e.y.sampleOffset))),Yl={[$t.TYPE]:$t},Nl=(n,e,t,s,o,i)=>{if(n.series.length===0||e.series.length===0)return[];const a=[];return n.series.forEach(l=>e.series.forEach(u=>{if(!Ul(l,u,i))return;let c=0n,d=0n;l.alignment<u.alignment?c=u.alignment-l.alignment:u.alignment<l.alignment&&(d=l.alignment-u.alignment);const f=r.math.min(r.bounds.span(l.alignmentBounds)-c,r.bounds.span(u.alignmentBounds)-d);if(f===0n)return;let p=r.clamp(Math.round(t*4*Number(f)),s,51);o!=="decimate"&&(p=1);const g=Number(f/l.alignmentMultiple),T=Number(c/l.alignmentMultiple),y=Number(d/u.alignmentMultiple);a.push({x:l,y:u,xOffset:T,yOffset:y,count:g,downsample:p})})),a},Zl=n=>n.map(e=>({...e,x:e.x.digest,y:e.y.digest})),Ul=(n,e,t)=>{if(n.alignmentMultiple!==e.alignmentMultiple)return console.warn("encountered two series with different alignment multiples in draw operations",{x:n.digest,y:e.digest}),!1;const s=n.timeRange.overlapsWith(e.timeRange,t),o=r.bounds.overlapsWith(n.alignmentBounds,e.alignmentBounds);return s&&o},Bs=h.z.object({dpr:h.z.number(),region:r.box.box,bootstrap:h.z.boolean().default(!1),bootstrapped:h.z.boolean().default(!1),glCanvas:h.z.any().optional(),upper2dCanvas:h.z.any().optional(),lower2dCanvas:h.z.any().optional(),os:r.runtime.osZ});class Ht extends w.Composite{static TYPE="Canvas";schema=Bs;renderCtx=null;afterUpdate(e){if(this.renderCtx==null){if(!this.state.bootstrap)return;const{glCanvas:t,lower2dCanvas:s,upper2dCanvas:o,os:i}=this.state;if(t==null||s==null||o==null)throw new x.UnexpectedError("[vis.worker.Canvas] - expected render context bootstrap to include all canvases");this.renderCtx=I.Context.create(e,t,s,o,i),_e.create(e,this.renderCtx),this.setState(a=>({...a,bootstrap:!1,bootstrapped:!0,glCanvas:void 0,lower2dCanvas:void 0,upper2dCanvas:void 0}))}else this.renderCtx.update(e);this.renderCtx.resize(this.state.region,this.state.dpr)}}const Wo={[Ht.TYPE]:Ht},Bl=Object.freeze(Object.defineProperty({__proto__:null,Canvas:Ht,REGISTRY:Wo,canvasStateZ:Bs},Symbol.toStringTag,{value:"Module"})),Fs=h.z.object({position:r.xy.xy,zoom:h.z.number(),region:r.box.box,clearOverScan:r.xy.crudeZ.default(5),visible:h.z.boolean().default(!0),autoRenderInterval:h.z.number().optional()}),vt=["upper2d","lower2d"];class xe extends w.Composite{static TYPE="Diagram";static stateZ=Fs;schema=xe.stateZ;afterUpdate(e){this.internal.renderCtx=I.Context.use(e),this.internal.handleError=w.useErrorHandler(e),r.primitive.isNonZero(this.state.autoRenderInterval)&&(this.internal.autoRenderInterval??=setInterval(()=>{this.state.visible&&this.requestRender("low")},this.state.autoRenderInterval)),on(e,()=>{this.state.visible&&this.requestRender("low")}),!(!this.state.visible&&!this.prevState.visible)&&(this.internal.viewportScale=r.scale.XY.magnify(r.xy.construct(this.state.zoom)).translate(r.box.topLeft(this.state.region)).translate(this.state.position),this.requestRender("high"))}afterDelete(){this.internal.autoRenderInterval!=null&&clearInterval(this.internal.autoRenderInterval),this.requestRender("high")}render(){if(this.deleted)return;const{renderCtx:e,handleError:t,viewportScale:s}=this.internal,o=r.box.construct(this.state.region);if(!this.state.visible)return()=>e.erase(o,this.state.clearOverScan,...vt);const i=e.scissor(o,r.xy.ZERO,vt);try{this.children.forEach(l=>l.render?.({viewportScale:s}))}catch(l){t(l,"failed to render diagram")}finally{i()}const a=r.box.copy(this.state.region);return()=>{e.lower2d.fillStyle=r.color.hex(r.color.BLACK),e.lower2d.fillRect(...r.xy.couple(r.box.topLeft(a)),r.box.width(a),r.box.height(a)),e.erase(a,this.state.clearOverScan,...vt)}}requestRender(e){const{renderCtx:t}=this.internal;t.loop.set({key:`${xe.TYPE}-${this.key}`,render:this.render.bind(this),priority:e,canvases:vt})}}const Vo={[xe.TYPE]:xe},Fl=Object.freeze(Object.defineProperty({__proto__:null,Diagram:xe,REGISTRY:Vo,diagramStateZ:Fs},Symbol.toStringTag,{value:"Module"}));function Lt(n,e){return n==null||e==null?NaN:n<e?-1:n>e?1:n>=e?0:NaN}function $l(n,e){return n==null||e==null?NaN:e<n?-1:e>n?1:e>=n?0:NaN}function $s(n){let e,t,s;n.length!==2?(e=Lt,t=(l,u)=>Lt(n(l),u),s=(l,u)=>n(l)-u):(e=n===Lt||n===$l?n:Hl,t=n,s=n);function o(l,u,c=0,d=l.length){if(c<d){if(e(u,u)!==0)return d;do{const f=c+d>>>1;t(l[f],u)<0?c=f+1:d=f}while(c<d)}return c}function i(l,u,c=0,d=l.length){if(c<d){if(e(u,u)!==0)return d;do{const f=c+d>>>1;t(l[f],u)<=0?c=f+1:d=f}while(c<d)}return c}function a(l,u,c=0,d=l.length){const f=o(l,u,c,d-1);return f>c&&s(l[f-1],u)>-s(l[f],u)?f-1:f}return{left:o,center:a,right:i}}function Hl(){return 0}function ql(n){return n===null?NaN:+n}const jl=$s(Lt),Wl=jl.right;$s(ql).center;const Vl=Math.sqrt(50),Xl=Math.sqrt(10),Gl=Math.sqrt(2);function qt(n,e,t){const s=(e-n)/Math.max(0,t),o=Math.floor(Math.log10(s)),i=s/Math.pow(10,o),a=i>=Vl?10:i>=Xl?5:i>=Gl?2:1;let l,u,c;return o<0?(c=Math.pow(10,-o)/a,l=Math.round(n*c),u=Math.round(e*c),l/c<n&&++l,u/c>e&&--u,c=-c):(c=Math.pow(10,o)*a,l=Math.round(n/c),u=Math.round(e/c),l*c<n&&++l,u*c>e&&--u),u<l&&.5<=t&&t<2?qt(n,e,t*2):[l,u,c]}function Kl(n,e,t){if(e=+e,n=+n,t=+t,!(t>0))return[];if(n===e)return[n];const s=e<n,[o,i,a]=s?qt(e,n,t):qt(n,e,t);if(!(i>=o))return[];const l=i-o+1,u=new Array(l);if(s)if(a<0)for(let c=0;c<l;++c)u[c]=(i-c)/-a;else for(let c=0;c<l;++c)u[c]=(i-c)*a;else if(a<0)for(let c=0;c<l;++c)u[c]=(o+c)/-a;else for(let c=0;c<l;++c)u[c]=(o+c)*a;return u}function Vn(n,e,t){return e=+e,n=+n,t=+t,qt(n,e,t)[2]}function Xn(n,e,t){e=+e,n=+n,t=+t;const s=e<n,o=s?Vn(e,n,t):Vn(n,e,t);return(s?-1:1)*(o<0?1/-o:o)}function Xo(n,e){switch(arguments.length){case 0:break;case 1:this.range(n);break;default:this.range(e).domain(n);break}return this}function Ql(n){return function(){return n}}function Jl(n){return+n}var gr=[0,1];function Pe(n){return n}function Gn(n,e){return(e-=n=+n)?function(t){return(t-n)/e}:Ql(isNaN(e)?NaN:.5)}function ec(n,e){var t;return n>e&&(t=n,n=e,e=t),function(s){return Math.max(n,Math.min(e,s))}}function tc(n,e,t){var s=n[0],o=n[1],i=e[0],a=e[1];return o<s?(s=Gn(o,s),i=t(a,i)):(s=Gn(s,o),i=t(i,a)),function(l){return i(s(l))}}function nc(n,e,t){var s=Math.min(n.length,e.length)-1,o=new Array(s),i=new Array(s),a=-1;for(n[s]<n[0]&&(n=n.slice().reverse(),e=e.slice().reverse());++a<s;)o[a]=Gn(n[a],n[a+1]),i[a]=t(e[a],e[a+1]);return function(l){var u=Wl(n,l,1,s)-1;return i[u](o[u](l))}}function Go(n,e){return e.domain(n.domain()).range(n.range()).interpolate(n.interpolate()).clamp(n.clamp()).unknown(n.unknown())}function sc(){var n=gr,e=gr,t=ln,s,o,i,a=Pe,l,u,c;function d(){var p=Math.min(n.length,e.length);return a!==Pe&&(a=ec(n[0],n[p-1])),l=p>2?nc:tc,u=c=null,f}function f(p){return p==null||isNaN(p=+p)?i:(u||(u=l(n.map(s),e,t)))(s(a(p)))}return f.invert=function(p){return a(o((c||(c=l(e,n.map(s),nt)))(p)))},f.domain=function(p){return arguments.length?(n=Array.from(p,Jl),d()):n.slice()},f.range=function(p){return arguments.length?(e=Array.from(p),d()):e.slice()},f.rangeRound=function(p){return e=Array.from(p),t=Ia,d()},f.clamp=function(p){return arguments.length?(a=p?!0:Pe,d()):a!==Pe},f.interpolate=function(p){return arguments.length?(t=p,d()):t},f.unknown=function(p){return arguments.length?(i=p,f):i},function(p,g){return s=p,o=g,d()}}function Ko(){return sc()(Pe,Pe)}function rc(n){return Math.abs(n=Math.round(n))>=1e21?n.toLocaleString("en").replace(/,/g,""):n.toString(10)}function jt(n,e){if(!isFinite(n)||n===0)return null;var t=(n=e?n.toExponential(e-1):n.toExponential()).indexOf("e"),s=n.slice(0,t);return[s.length>1?s[0]+s.slice(2):s,+n.slice(t+1)]}function Ze(n){return n=jt(Math.abs(n)),n?n[1]:NaN}function oc(n,e){return function(t,s){for(var o=t.length,i=[],a=0,l=n[0],u=0;o>0&&l>0&&(u+l+1>s&&(l=Math.max(1,s-u)),i.push(t.substring(o-=l,o+l)),!((u+=l+1)>s));)l=n[a=(a+1)%n.length];return i.reverse().join(e)}}function ic(n){return function(e){return e.replace(/[0-9]/g,function(t){return n[+t]})}}var ac=/^(?:(.)?([<>=^]))?([+\-( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;function Wt(n){if(!(e=ac.exec(n)))throw new Error("invalid format: "+n);var e;return new Hs({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]})}Wt.prototype=Hs.prototype;function Hs(n){this.fill=n.fill===void 0?" ":n.fill+"",this.align=n.align===void 0?">":n.align+"",this.sign=n.sign===void 0?"-":n.sign+"",this.symbol=n.symbol===void 0?"":n.symbol+"",this.zero=!!n.zero,this.width=n.width===void 0?void 0:+n.width,this.comma=!!n.comma,this.precision=n.precision===void 0?void 0:+n.precision,this.trim=!!n.trim,this.type=n.type===void 0?"":n.type+""}Hs.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 lc(n){e:for(var e=n.length,t=1,s=-1,o;t<e;++t)switch(n[t]){case".":s=o=t;break;case"0":s===0&&(s=t),o=t;break;default:if(!+n[t])break e;s>0&&(s=0);break}return s>0?n.slice(0,s)+n.slice(o+1):n}var Vt;function cc(n,e){var t=jt(n,e);if(!t)return Vt=void 0,n.toPrecision(e);var s=t[0],o=t[1],i=o-(Vt=Math.max(-8,Math.min(8,Math.floor(o/3)))*3)+1,a=s.length;return i===a?s:i>a?s+new Array(i-a+1).join("0"):i>0?s.slice(0,i)+"."+s.slice(i):"0."+new Array(1-i).join("0")+jt(n,Math.max(0,e+i-1))[0]}function yr(n,e){var t=jt(n,e);if(!t)return n+"";var s=t[0],o=t[1];return o<0?"0."+new Array(-o).join("0")+s:s.length>o+1?s.slice(0,o+1)+"."+s.slice(o+1):s+new Array(o-s.length+2).join("0")}const xr={"%":(n,e)=>(n*100).toFixed(e),b:n=>Math.round(n).toString(2),c:n=>n+"",d:rc,e:(n,e)=>n.toExponential(e),f:(n,e)=>n.toFixed(e),g:(n,e)=>n.toPrecision(e),o:n=>Math.round(n).toString(8),p:(n,e)=>yr(n*100,e),r:yr,s:cc,X:n=>Math.round(n).toString(16).toUpperCase(),x:n=>Math.round(n).toString(16)};function br(n){return n}var Sr=Array.prototype.map,Tr=["y","z","a","f","p","n","µ","m","","k","M","G","T","P","E","Z","Y"];function uc(n){var e=n.grouping===void 0||n.thousands===void 0?br:oc(Sr.call(n.grouping,Number),n.thousands+""),t=n.currency===void 0?"":n.currency[0]+"",s=n.currency===void 0?"":n.currency[1]+"",o=n.decimal===void 0?".":n.decimal+"",i=n.numerals===void 0?br:ic(Sr.call(n.numerals,String)),a=n.percent===void 0?"%":n.percent+"",l=n.minus===void 0?"−":n.minus+"",u=n.nan===void 0?"NaN":n.nan+"";function c(f,p){f=Wt(f);var g=f.fill,T=f.align,y=f.sign,v=f.symbol,R=f.zero,L=f.width,k=f.comma,C=f.precision,Z=f.trim,b=f.type;b==="n"?(k=!0,b="g"):xr[b]||(C===void 0&&(C=12),Z=!0,b="g"),(R||g==="0"&&T==="=")&&(R=!0,g="0",T="=");var M=(p&&p.prefix!==void 0?p.prefix:"")+(v==="$"?t:v==="#"&&/[boxX]/.test(b)?"0"+b.toLowerCase():""),A=(v==="$"?s:/[%p]/.test(b)?a:"")+(p&&p.suffix!==void 0?p.suffix:""),V=xr[b],K=/[defgprs%]/.test(b);C=C===void 0?6:/[gprs]/.test(b)?Math.max(1,Math.min(21,C)):Math.max(0,Math.min(20,C));function ue(E){var $=M,N=A,Q,de,ne;if(b==="c")N=V(E)+N,E="";else{E=+E;var J=E<0||1/E<0;if(E=isNaN(E)?u:V(Math.abs(E),C),Z&&(E=lc(E)),J&&+E==0&&y!=="+"&&(J=!1),$=(J?y==="("?y:l:y==="-"||y==="("?"":y)+$,N=(b==="s"&&!isNaN(E)&&Vt!==void 0?Tr[8+Vt/3]:"")+N+(J&&y==="("?")":""),K){for(Q=-1,de=E.length;++Q<de;)if(ne=E.charCodeAt(Q),48>ne||ne>57){N=(ne===46?o+E.slice(Q+1):E.slice(Q))+N,E=E.slice(0,Q);break}}}k&&!R&&(E=e(E,1/0));var se=$.length+E.length+N.length,H=se<L?new Array(L-se+1).join(g):"";switch(k&&R&&(E=e(H+E,H.length?L-N.length:1/0),H=""),T){case"<":E=$+E+N+H;break;case"=":E=$+H+E+N;break;case"^":E=H.slice(0,se=H.length>>1)+$+E+N+H.slice(se);break;default:E=H+$+E+N;break}return i(E)}return ue.toString=function(){return f+""},ue}function d(f,p){var g=Math.max(-8,Math.min(8,Math.floor(Ze(p)/3)))*3,T=Math.pow(10,-g),y=c((f=Wt(f),f.type="f",f),{suffix:Tr[8+g/3]});return function(v){return y(T*v)}}return{format:c,formatPrefix:d}}var wt,Qo,Jo;hc({thousands:",",grouping:[3],currency:["$",""]});function hc(n){return wt=uc(n),Qo=wt.format,Jo=wt.formatPrefix,wt}function dc(n){return Math.max(0,-Ze(Math.abs(n)))}function fc(n,e){return Math.max(0,Math.max(-8,Math.min(8,Math.floor(Ze(e)/3)))*3-Ze(Math.abs(n)))}function pc(n,e){return n=Math.abs(n),e=Math.abs(e)-n,Math.max(0,Ze(e)-Ze(n))+1}function mc(n,e,t,s){var o=Xn(n,e,t),i;switch(s=Wt(s??",f"),s.type){case"s":{var a=Math.max(Math.abs(n),Math.abs(e));return s.precision==null&&!isNaN(i=fc(o,a))&&(s.precision=i),Jo(s,a)}case"":case"e":case"g":case"p":case"r":{s.precision==null&&!isNaN(i=pc(o,Math.max(Math.abs(n),Math.abs(e))))&&(s.precision=i-(s.type==="e"));break}case"f":case"%":{s.precision==null&&!isNaN(i=dc(o))&&(s.precision=i-(s.type==="%")*2);break}}return Qo(s)}function gc(n){var e=n.domain;return n.ticks=function(t){var s=e();return Kl(s[0],s[s.length-1],t??10)},n.tickFormat=function(t,s){var o=e();return mc(o[0],o[o.length-1],t??10,s)},n.nice=function(t){t==null&&(t=10);var s=e(),o=0,i=s.length-1,a=s[o],l=s[i],u,c,d=10;for(l<a&&(c=a,a=l,l=c,c=o,o=i,i=c);d-- >0;){if(c=Vn(a,l,t),c===u)return s[o]=a,s[i]=l,e(s);if(c>0)a=Math.floor(a/c)*c,l=Math.ceil(l/c)*c;else if(c<0)a=Math.ceil(a*c)/c,l=Math.floor(l*c)/c;else break;u=c}return n},n}function ei(){var n=Ko();return n.copy=function(){return Go(n,ei())},Xo.apply(n,arguments),gc(n)}function yc(n,e){n=n.slice();var t=0,s=n.length-1,o=n[t],i=n[s],a;return i<o&&(a=t,t=s,s=a,a=o,o=i,i=a),n[t]=e.floor(o),n[s]=e.ceil(i),n}const Pn=new Date,Ln=new Date;function z(n,e,t,s){function o(i){return n(i=arguments.length===0?new Date:new Date(+i)),i}return o.floor=i=>(n(i=new Date(+i)),i),o.ceil=i=>(n(i=new Date(i-1)),e(i,1),n(i),i),o.round=i=>{const a=o(i),l=o.ceil(i);return i-a<l-i?a:l},o.offset=(i,a)=>(e(i=new Date(+i),a==null?1:Math.floor(a)),i),o.range=(i,a,l)=>{const u=[];if(i=o.ceil(i),l=l==null?1:Math.floor(l),!(i<a)||!(l>0))return u;let c;do u.push(c=new Date(+i)),e(i,l),n(i);while(c<i&&i<a);return u},o.filter=i=>z(a=>{if(a>=a)for(;n(a),!i(a);)a.setTime(a-1)},(a,l)=>{if(a>=a)if(l<0)for(;++l<=0;)for(;e(a,-1),!i(a););else for(;--l>=0;)for(;e(a,1),!i(a););}),t&&(o.count=(i,a)=>(Pn.setTime(+i),Ln.setTime(+a),n(Pn),n(Ln),Math.floor(t(Pn,Ln))),o.every=i=>(i=Math.floor(i),!isFinite(i)||!(i>0)?null:i>1?o.filter(s?a=>s(a)%i===0:a=>o.count(0,a)%i===0):o)),o}const Xt=z(()=>{},(n,e)=>{n.setTime(+n+e)},(n,e)=>e-n);Xt.every=n=>(n=Math.floor(n),!isFinite(n)||!(n>0)?null:n>1?z(e=>{e.setTime(Math.floor(e/n)*n)},(e,t)=>{e.setTime(+e+t*n)},(e,t)=>(t-e)/n):Xt);Xt.range;const re=1e3,X=re*60,oe=X*60,ae=oe*24,qs=ae*7,vr=ae*30,kn=ae*365,Le=z(n=>{n.setTime(n-n.getMilliseconds())},(n,e)=>{n.setTime(+n+e*re)},(n,e)=>(e-n)/re,n=>n.getUTCSeconds());Le.range;const js=z(n=>{n.setTime(n-n.getMilliseconds()-n.getSeconds()*re)},(n,e)=>{n.setTime(+n+e*X)},(n,e)=>(e-n)/X,n=>n.getMinutes());js.range;const xc=z(n=>{n.setUTCSeconds(0,0)},(n,e)=>{n.setTime(+n+e*X)},(n,e)=>(e-n)/X,n=>n.getUTCMinutes());xc.range;const Ws=z(n=>{n.setTime(n-n.getMilliseconds()-n.getSeconds()*re-n.getMinutes()*X)},(n,e)=>{n.setTime(+n+e*oe)},(n,e)=>(e-n)/oe,n=>n.getHours());Ws.range;const bc=z(n=>{n.setUTCMinutes(0,0,0)},(n,e)=>{n.setTime(+n+e*oe)},(n,e)=>(e-n)/oe,n=>n.getUTCHours());bc.range;const gt=z(n=>n.setHours(0,0,0,0),(n,e)=>n.setDate(n.getDate()+e),(n,e)=>(e-n-(e.getTimezoneOffset()-n.getTimezoneOffset())*X)/ae,n=>n.getDate()-1);gt.range;const Vs=z(n=>{n.setUTCHours(0,0,0,0)},(n,e)=>{n.setUTCDate(n.getUTCDate()+e)},(n,e)=>(e-n)/ae,n=>n.getUTCDate()-1);Vs.range;const Sc=z(n=>{n.setUTCHours(0,0,0,0)},(n,e)=>{n.setUTCDate(n.getUTCDate()+e)},(n,e)=>(e-n)/ae,n=>Math.floor(n/ae));Sc.range;function Te(n){return z(e=>{e.setDate(e.getDate()-(e.getDay()+7-n)%7),e.setHours(0,0,0,0)},(e,t)=>{e.setDate(e.getDate()+t*7)},(e,t)=>(t-e-(t.getTimezoneOffset()-e.getTimezoneOffset())*X)/qs)}const yn=Te(0),Gt=Te(1),Tc=Te(2),vc=Te(3),Ue=Te(4),wc=Te(5),Ec=Te(6);yn.range;Gt.range;Tc.range;vc.range;Ue.range;wc.range;Ec.range;function ve(n){return z(e=>{e.setUTCDate(e.getUTCDate()-(e.getUTCDay()+7-n)%7),e.setUTCHours(0,0,0,0)},(e,t)=>{e.setUTCDate(e.getUTCDate()+t*7)},(e,t)=>(t-e)/qs)}const ti=ve(0),Kt=ve(1),Cc=ve(2),Rc=ve(3),Be=ve(4),Pc=ve(5),Lc=ve(6);ti.range;Kt.range;Cc.range;Rc.range;Be.range;Pc.range;Lc.range;const Xs=z(n=>{n.setDate(1),n.setHours(0,0,0,0)},(n,e)=>{n.setMonth(n.getMonth()+e)},(n,e)=>e.getMonth()-n.getMonth()+(e.getFullYear()-n.getFullYear())*12,n=>n.getMonth());Xs.range;const kc=z(n=>{n.setUTCDate(1),n.setUTCHours(0,0,0,0)},(n,e)=>{n.setUTCMonth(n.getUTCMonth()+e)},(n,e)=>e.getUTCMonth()-n.getUTCMonth()+(e.getUTCFullYear()-n.getUTCFullYear())*12,n=>n.getUTCMonth());kc.range;const le=z(n=>{n.setMonth(0,1),n.setHours(0,0,0,0)},(n,e)=>{n.setFullYear(n.getFullYear()+e)},(n,e)=>e.getFullYear()-n.getFullYear(),n=>n.getFullYear());le.every=n=>!isFinite(n=Math.floor(n))||!(n>0)?null:z(e=>{e.setFullYear(Math.floor(e.getFullYear()/n)*n),e.setMonth(0,1),e.setHours(0,0,0,0)},(e,t)=>{e.setFullYear(e.getFullYear()+t*n)});le.range;const be=z(n=>{n.setUTCMonth(0,1),n.setUTCHours(0,0,0,0)},(n,e)=>{n.setUTCFullYear(n.getUTCFullYear()+e)},(n,e)=>e.getUTCFullYear()-n.getUTCFullYear(),n=>n.getUTCFullYear());be.every=n=>!isFinite(n=Math.floor(n))||!(n>0)?null:z(e=>{e.setUTCFullYear(Math.floor(e.getUTCFullYear()/n)*n),e.setUTCMonth(0,1),e.setUTCHours(0,0,0,0)},(e,t)=>{e.setUTCFullYear(e.getUTCFullYear()+t*n)});be.range;function _c(n,e,t,s,o,i){const a=[[Le,1,re],[Le,5,5*re],[Le,15,15*re],[Le,30,30*re],[i,1,X],[i,5,5*X],[i,15,15*X],[i,30,30*X],[o,1,oe],[o,3,3*oe],[o,6,6*oe],[o,12,12*oe],[s,1,ae],[s,2,2*ae],[t,1,qs],[e,1,vr],[e,3,3*vr],[n,1,kn]];function l(c,d,f){const p=d<c;p&&([c,d]=[d,c]);const g=f&&typeof f.range=="function"?f:u(c,d,f),T=g?g.range(c,+d+1):[];return p?T.reverse():T}function u(c,d,f){const p=Math.abs(d-c)/f,g=$s(([,,v])=>v).right(a,p);if(g===a.length)return n.every(Xn(c/kn,d/kn,f));if(g===0)return Xt.every(Math.max(Xn(c,d,f),1));const[T,y]=a[p/a[g-1][2]<a[g][2]/p?g-1:g];return T.every(y)}return[l,u]}const[Oc,Mc]=_c(le,Xs,yn,gt,Ws,js);function _n(n){if(0<=n.y&&n.y<100){var e=new Date(-1,n.m,n.d,n.H,n.M,n.S,n.L);return e.setFullYear(n.y),e}return new Date(n.y,n.m,n.d,n.H,n.M,n.S,n.L)}function On(n){if(0<=n.y&&n.y<100){var e=new Date(Date.UTC(-1,n.m,n.d,n.H,n.M,n.S,n.L));return e.setUTCFullYear(n.y),e}return new Date(Date.UTC(n.y,n.m,n.d,n.H,n.M,n.S,n.L))}function je(n,e,t){return{y:n,m:e,d:t,H:0,M:0,S:0,L:0}}function Dc(n){var e=n.dateTime,t=n.date,s=n.time,o=n.periods,i=n.days,a=n.shortDays,l=n.months,u=n.shortMonths,c=We(o),d=Ve(o),f=We(i),p=Ve(i),g=We(a),T=Ve(a),y=We(l),v=Ve(l),R=We(u),L=Ve(u),k={a:ne,A:J,b:se,B:H,c:null,d:Lr,e:Lr,f:nu,g:du,G:pu,H:Jc,I:eu,j:tu,L:ni,m:su,M:ru,p:xn,q:bn,Q:Or,s:Mr,S:ou,u:iu,U:au,V:lu,w:cu,W:uu,x:null,X:null,y:hu,Y:fu,Z:mu,"%":_r},C={a:Sn,A:Tn,b:vn,B:bt,c:null,d:kr,e:kr,f:bu,g:ku,G:Ou,H:gu,I:yu,j:xu,L:ri,m:Su,M:Tu,p:wn,q:qi,Q:Or,s:Mr,S:vu,u:wu,U:Eu,V:Cu,w:Ru,W:Pu,x:null,X:null,y:Lu,Y:_u,Z:Mu,"%":_r},Z={a:K,A:ue,b:E,B:$,c:N,d:Rr,e:Rr,f:Xc,g:Cr,G:Er,H:Pr,I:Pr,j:qc,L:Vc,m:Hc,M:jc,p:V,q:$c,Q:Kc,s:Qc,S:Wc,u:Nc,U:Zc,V:Uc,w:Yc,W:Bc,x:Q,X:de,y:Cr,Y:Er,Z:Fc,"%":Gc};k.x=b(t,k),k.X=b(s,k),k.c=b(e,k),C.x=b(t,C),C.X=b(s,C),C.c=b(e,C);function b(S,P){return function(_){var m=[],B=-1,D=0,q=S.length,j,fe,nr;for(_ instanceof Date||(_=new Date(+_));++B<q;)S.charCodeAt(B)===37&&(m.push(S.slice(D,B)),(fe=wr[j=S.charAt(++B)])!=null?j=S.charAt(++B):fe=j==="e"?" ":"0",(nr=P[j])&&(j=nr(_,fe)),m.push(j),D=B+1);return m.push(S.slice(D,B)),m.join("")}}function M(S,P){return function(_){var m=je(1900,void 0,1),B=A(m,S,_+="",0),D,q;if(B!=_.length)return null;if("Q"in m)return new Date(m.Q);if("s"in m)return new Date(m.s*1e3+("L"in m?m.L:0));if(P&&!("Z"in m)&&(m.Z=0),"p"in m&&(m.H=m.H%12+m.p*12),m.m===void 0&&(m.m="q"in m?m.q:0),"V"in m){if(m.V<1||m.V>53)return null;"w"in m||(m.w=1),"Z"in m?(D=On(je(m.y,0,1)),q=D.getUTCDay(),D=q>4||q===0?Kt.ceil(D):Kt(D),D=Vs.offset(D,(m.V-1)*7),m.y=D.getUTCFullYear(),m.m=D.getUTCMonth(),m.d=D.getUTCDate()+(m.w+6)%7):(D=_n(je(m.y,0,1)),q=D.getDay(),D=q>4||q===0?Gt.ceil(D):Gt(D),D=gt.offset(D,(m.V-1)*7),m.y=D.getFullYear(),m.m=D.getMonth(),m.d=D.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),q="Z"in m?On(je(m.y,0,1)).getUTCDay():_n(je(m.y,0,1)).getDay(),m.m=0,m.d="W"in m?(m.w+6)%7+m.W*7-(q+5)%7:m.w+m.U*7-(q+6)%7);return"Z"in m?(m.H+=m.Z/100|0,m.M+=m.Z%100,On(m)):_n(m)}}function A(S,P,_,m){for(var B=0,D=P.length,q=_.length,j,fe;B<D;){if(m>=q)return-1;if(j=P.charCodeAt(B++),j===37){if(j=P.charAt(B++),fe=Z[j in wr?P.charAt(B++):j],!fe||(m=fe(S,_,m))<0)return-1}else if(j!=_.charCodeAt(m++))return-1}return m}function V(S,P,_){var m=c.exec(P.slice(_));return m?(S.p=d.get(m[0].toLowerCase()),_+m[0].length):-1}function K(S,P,_){var m=g.exec(P.slice(_));return m?(S.w=T.get(m[0].toLowerCase()),_+m[0].length):-1}function ue(S,P,_){var m=f.exec(P.slice(_));return m?(S.w=p.get(m[0].toLowerCase()),_+m[0].length):-1}function E(S,P,_){var m=R.exec(P.slice(_));return m?(S.m=L.get(m[0].toLowerCase()),_+m[0].length):-1}function $(S,P,_){var m=y.exec(P.slice(_));return m?(S.m=v.get(m[0].toLowerCase()),_+m[0].length):-1}function N(S,P,_){return A(S,e,P,_)}function Q(S,P,_){return A(S,t,P,_)}function de(S,P,_){return A(S,s,P,_)}function ne(S){return a[S.getDay()]}function J(S){return i[S.getDay()]}function se(S){return u[S.getMonth()]}function H(S){return l[S.getMonth()]}function xn(S){return o[+(S.getHours()>=12)]}function bn(S){return 1+~~(S.getMonth()/3)}function Sn(S){return a[S.getUTCDay()]}function Tn(S){return i[S.getUTCDay()]}function vn(S){return u[S.getUTCMonth()]}function bt(S){return l[S.getUTCMonth()]}function wn(S){return o[+(S.getUTCHours()>=12)]}function qi(S){return 1+~~(S.getUTCMonth()/3)}return{format:function(S){var P=b(S+="",k);return P.toString=function(){return S},P},parse:function(S){var P=M(S+="",!1);return P.toString=function(){return S},P},utcFormat:function(S){var P=b(S+="",C);return P.toString=function(){return S},P},utcParse:function(S){var P=M(S+="",!0);return P.toString=function(){return S},P}}}var wr={"-":"",_:" ",0:"0"},Y=/^\s*\d+/,Ac=/^%/,Ic=/[\\^$*+?|[\]().{}]/g;function O(n,e,t){var s=n<0?"-":"",o=(s?-n:n)+"",i=o.length;return s+(i<t?new Array(t-i+1).join(e)+o:o)}function zc(n){return n.replace(Ic,"\\$&")}function We(n){return new RegExp("^(?:"+n.map(zc).join("|")+")","i")}function Ve(n){return new Map(n.map((e,t)=>[e.toLowerCase(),t]))}function Yc(n,e,t){var s=Y.exec(e.slice(t,t+1));return s?(n.w=+s[0],t+s[0].length):-1}function Nc(n,e,t){var s=Y.exec(e.slice(t,t+1));return s?(n.u=+s[0],t+s[0].length):-1}function Zc(n,e,t){var s=Y.exec(e.slice(t,t+2));return s?(n.U=+s[0],t+s[0].length):-1}function Uc(n,e,t){var s=Y.exec(e.slice(t,t+2));return s?(n.V=+s[0],t+s[0].length):-1}function Bc(n,e,t){var s=Y.exec(e.slice(t,t+2));return s?(n.W=+s[0],t+s[0].length):-1}function Er(n,e,t){var s=Y.exec(e.slice(t,t+4));return s?(n.y=+s[0],t+s[0].length):-1}function Cr(n,e,t){var s=Y.exec(e.slice(t,t+2));return s?(n.y=+s[0]+(+s[0]>68?1900:2e3),t+s[0].length):-1}function Fc(n,e,t){var s=/^(Z)|([+-]\d\d)(?::?(\d\d))?/.exec(e.slice(t,t+6));return s?(n.Z=s[1]?0:-(s[2]+(s[3]||"00")),t+s[0].length):-1}function $c(n,e,t){var s=Y.exec(e.slice(t,t+1));return s?(n.q=s[0]*3-3,t+s[0].length):-1}function Hc(n,e,t){var s=Y.exec(e.slice(t,t+2));return s?(n.m=s[0]-1,t+s[0].length):-1}function Rr(n,e,t){var s=Y.exec(e.slice(t,t+2));return s?(n.d=+s[0],t+s[0].length):-1}function qc(n,e,t){var s=Y.exec(e.slice(t,t+3));return s?(n.m=0,n.d=+s[0],t+s[0].length):-1}function Pr(n,e,t){var s=Y.exec(e.slice(t,t+2));return s?(n.H=+s[0],t+s[0].length):-1}function jc(n,e,t){var s=Y.exec(e.slice(t,t+2));return s?(n.M=+s[0],t+s[0].length):-1}function Wc(n,e,t){var s=Y.exec(e.slice(t,t+2));return s?(n.S=+s[0],t+s[0].length):-1}function Vc(n,e,t){var s=Y.exec(e.slice(t,t+3));return s?(n.L=+s[0],t+s[0].length):-1}function Xc(n,e,t){var s=Y.exec(e.slice(t,t+6));return s?(n.L=Math.floor(s[0]/1e3),t+s[0].length):-1}function Gc(n,e,t){var s=Ac.exec(e.slice(t,t+1));return s?t+s[0].length:-1}function Kc(n,e,t){var s=Y.exec(e.slice(t));return s?(n.Q=+s[0],t+s[0].length):-1}function Qc(n,e,t){var s=Y.exec(e.slice(t));return s?(n.s=+s[0],t+s[0].length):-1}function Lr(n,e){return O(n.getDate(),e,2)}function Jc(n,e){return O(n.getHours(),e,2)}function eu(n,e){return O(n.getHours()%12||12,e,2)}function tu(n,e){return O(1+gt.count(le(n),n),e,3)}function ni(n,e){return O(n.getMilliseconds(),e,3)}function nu(n,e){return ni(n,e)+"000"}function su(n,e){return O(n.getMonth()+1,e,2)}function ru(n,e){return O(n.getMinutes(),e,2)}function ou(n,e){return O(n.getSeconds(),e,2)}function iu(n){var e=n.getDay();return e===0?7:e}function au(n,e){return O(yn.count(le(n)-1,n),e,2)}function si(n){var e=n.getDay();return e>=4||e===0?Ue(n):Ue.ceil(n)}function lu(n,e){return n=si(n),O(Ue.count(le(n),n)+(le(n).getDay()===4),e,2)}function cu(n){return n.getDay()}function uu(n,e){return O(Gt.count(le(n)-1,n),e,2)}function hu(n,e){return O(n.getFullYear()%100,e,2)}function du(n,e){return n=si(n),O(n.getFullYear()%100,e,2)}function fu(n,e){return O(n.getFullYear()%1e4,e,4)}function pu(n,e){var t=n.getDay();return n=t>=4||t===0?Ue(n):Ue.ceil(n),O(n.getFullYear()%1e4,e,4)}function mu(n){var e=n.getTimezoneOffset();return(e>0?"-":(e*=-1,"+"))+O(e/60|0,"0",2)+O(e%60,"0",2)}function kr(n,e){return O(n.getUTCDate(),e,2)}function gu(n,e){return O(n.getUTCHours(),e,2)}function yu(n,e){return O(n.getUTCHours()%12||12,e,2)}function xu(n,e){return O(1+Vs.count(be(n),n),e,3)}function ri(n,e){return O(n.getUTCMilliseconds(),e,3)}function bu(n,e){return ri(n,e)+"000"}function Su(n,e){return O(n.getUTCMonth()+1,e,2)}function Tu(n,e){return O(n.getUTCMinutes(),e,2)}function vu(n,e){return O(n.getUTCSeconds(),e,2)}function wu(n){var e=n.getUTCDay();return e===0?7:e}function Eu(n,e){return O(ti.count(be(n)-1,n),e,2)}function oi(n){var e=n.getUTCDay();return e>=4||e===0?Be(n):Be.ceil(n)}function Cu(n,e){return n=oi(n),O(Be.count(be(n),n)+(be(n).getUTCDay()===4),e,2)}function Ru(n){return n.getUTCDay()}function Pu(n,e){return O(Kt.count(be(n)-1,n),e,2)}function Lu(n,e){return O(n.getUTCFullYear()%100,e,2)}function ku(n,e){return n=oi(n),O(n.getUTCFullYear()%100,e,2)}function _u(n,e){return O(n.getUTCFullYear()%1e4,e,4)}function Ou(n,e){var t=n.getUTCDay();return n=t>=4||t===0?Be(n):Be.ceil(n),O(n.getUTCFullYear()%1e4,e,4)}function Mu(){return"+0000"}function _r(){return"%"}function Or(n){return+n}function Mr(n){return Math.floor(+n/1e3)}var Ce,ii;Du({dateTime:"%x, %X",date:"%-m/%-d/%Y",time:"%-I:%M:%S %p",periods:["AM","PM"],days:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],shortDays:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],months:["January","February","March","April","May","June","July","August","September","October","November","December"],shortMonths:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]});function Du(n){return Ce=Dc(n),ii=Ce.format,Ce.parse,Ce.utcFormat,Ce.utcParse,Ce}function Au(n){return new Date(n)}function Iu(n){return n instanceof Date?+n:+new Date(+n)}function ai(n,e,t,s,o,i,a,l,u,c){var d=Ko(),f=d.invert,p=d.domain,g=c(".%L"),T=c(":%S"),y=c("%I:%M"),v=c("%I %p"),R=c("%a %d"),L=c("%b %d"),k=c("%B"),C=c("%Y");function Z(b){return(u(b)<b?g:l(b)<b?T:a(b)<b?y:i(b)<b?v:s(b)<b?o(b)<b?R:L:t(b)<b?k:C)(b)}return d.invert=function(b){return new Date(f(b))},d.domain=function(b){return arguments.length?p(Array.from(b,Iu)):p().map(Au)},d.ticks=function(b){var M=p();return n(M[0],M[M.length-1],b??10)},d.tickFormat=function(b,M){return M==null?Z:c(M)},d.nice=function(b){var M=p();return(!b||typeof b.range!="function")&&(b=e(M[0],M[M.length-1],b??10)),b?p(yc(M,b)):d},d.copy=function(){return Go(d,ai(n,e,t,s,o,i,a,l,u,c))},d}function zu(){return Xo.apply(ai(Oc,Mc,le,Xs,yn,gt,Ws,js,Le,ii).domain([new Date(2e3,0,1),new Date(2e3,0,2)]),arguments)}const Dr=[r.TimeSpan.NANOSECOND,r.TimeSpan.nanoseconds(2),r.TimeSpan.nanoseconds(5),r.TimeSpan.nanoseconds(10),r.TimeSpan.nanoseconds(20),r.TimeSpan.nanoseconds(50),r.TimeSpan.nanoseconds(100),r.TimeSpan.nanoseconds(200),r.TimeSpan.nanoseconds(500),r.TimeSpan.MICROSECOND,r.TimeSpan.microseconds(2),r.TimeSpan.microseconds(5),r.TimeSpan.microseconds(10),r.TimeSpan.microseconds(20),r.TimeSpan.microseconds(50),r.TimeSpan.microseconds(100),r.TimeSpan.microseconds(200),r.TimeSpan.microseconds(500),r.TimeSpan.MILLISECOND,r.TimeSpan.milliseconds(2),r.TimeSpan.milliseconds(5),r.TimeSpan.milliseconds(10),r.TimeSpan.milliseconds(20),r.TimeSpan.milliseconds(50),r.TimeSpan.milliseconds(100),r.TimeSpan.milliseconds(200),r.TimeSpan.milliseconds(500),r.TimeSpan.SECOND];class Yu{_domain;_range;_span;constructor(){this._domain=[new r.TimeStamp(0n),new r.TimeStamp(1n)],this._range=[0,1],this._span=this._domain[1].span(this._domain[0])}domain(e){return e===void 0?this._domain:(this._domain=[new r.TimeStamp(e[0]),new r.TimeStamp(e[1])],this._span=this._domain[1].span(this._domain[0]),this)}range(e){return e===void 0?this._range:(this._range=e,this)}scale(e){const s=new r.TimeStamp(e).valueOf(),o=this._domain[0].valueOf(),i=this._domain[1].valueOf()-o,a=this._range[1]-this._range[0];return Number(s-o)/Number(i)*a+this._range[0]}ticks(e){const t=this.calculateOptimalStep(e).valueOf(),s=this._domain[0].valueOf(),o=this._domain[1].valueOf(),i=(s+t-1n)/t*t,a=Number((o-i)/t);return Array.from({length:a+1},(l,u)=>{const c=i+BigInt(u)*t;return new r.TimeStamp(c)}).filter(l=>l.afterEq(this._domain[0])&&l.beforeEq(this._domain[1]))}calculateOptimalStep(e){const t=this._span.valueOf()/BigInt(Math.ceil(e));let s=Dr[0];for(const o of Dr){if(o.valueOf()>t)break;s=o}return s}formatTick(e){return this._span.lessThan(r.TimeSpan.microseconds(50))?`${e.remainder(r.TimeSpan.MILLISECOND).microseconds.toString()}µs`:`${e.remainder(r.TimeSpan.SECOND).milliseconds.toString()}ms`}}const Nu=()=>new Yu,Gs=h.z.enum(["linear","time"]),Ks=h.z.object({tickSpacing:h.z.number().default(75),type:Gs.default("linear")}),Kn=n=>{const e=Ks.parse(n);return Bu[e.type](e)};class Zu{props;prevScaleSize;prevDomain;currTicks;normalScale;preciseScale;constructor(e){this.props=e,this.normalScale=zu(),this.preciseScale=Nu(),this.prevScaleSize=0,this.prevDomain=new r.TimeRange(new r.TimeStamp(0),new r.TimeStamp(0)),this.currTicks=[]}create({decimalToDataScale:e,size:t}){const s=new r.TimeRange(new r.TimeStamp(e.pos(0)),new r.TimeStamp(e.pos(1)));if(this.prevDomain.equals(s)&&this.prevScaleSize===t)return this.currTicks;if(this.prevDomain=s,this.prevScaleSize!==t){const o=[0,t];this.preciseScale.range(o),this.normalScale.range(o),this.prevScaleSize=t}if(s.span.milliseconds<5){this.preciseScale.domain([s.start,s.end]);const o=Qn(t,this.props.tickSpacing)/2,i=this.preciseScale.ticks(o);this.currTicks=i.map(a=>({label:this.preciseScale.formatTick(a),position:this.preciseScale.scale(a)}))}else{this.normalScale.domain([s.start.date(),s.end.date()]);const o=this.normalScale.ticks(Qn(t,this.props.tickSpacing));this.currTicks=o.map(i=>({label:this.normalTickLabel(i),position:this.normalScale(i)}))}return this.currTicks}normalTickLabel(e){let t=`:${e.getSeconds()}`;const s=e.getMilliseconds();if(s!==0){const o=Math.round(e.getMilliseconds()).toString().padStart(3,"0").replace(/0+$/,"");t+=`.${o}`}return e.getSeconds()===0&&s===0&&(t=`${e.getHours()}:${e.getMinutes().toString().padStart(2,"0")}`),t}}class Uu{props;prevDomain;prevScaleSize;currTicks;d3Scale;constructor(e){this.props=e,this.prevDomain=r.bounds.construct(0,0),this.prevScaleSize=0,this.currTicks=[],this.d3Scale=ei()}create({decimalToDataScale:e,size:t}){const s={lower:e.pos(0),upper:e.pos(1)};if(r.bounds.equals(this.prevDomain,s)&&this.prevScaleSize===t)return this.currTicks;r.bounds.equals(this.prevDomain,s)||(this.d3Scale=this.d3Scale.domain([s.lower,s.upper])),this.prevScaleSize!==t&&(this.d3Scale=this.d3Scale.range([0,t])),this.prevDomain=s,this.prevScaleSize=t;const o=Qn(t,this.props.tickSpacing),i=this.d3Scale.ticks(o);return this.currTicks=i.map(a=>({label:this.tickLabel(a),position:this.d3Scale(a)})),this.currTicks}tickLabel(e){return e.toString()}}const Qn=(n,e)=>{const t=Math.floor(n/e);return t>0?t:1},Bu={linear:n=>new Uu(n),time:n=>new Zu(n)},Qs=Ks.extend({color:r.color.colorZ,type:Gs.default("linear"),font:h.z.string(),showGrid:h.z.boolean().default(!0),location:r.location.outer,gridColor:r.color.colorZ}),G=5,rt=6,yt={useAtlas:!0},Fu={bottom:(n,e)=>new ci(n,e),top:(n,e)=>new ui(n,e),left:(n,e)=>new $u(n,e),right:(n,e)=>new hi(n,e)},li=(n,e,t)=>Fu[n](e,t);class we{renderCtx;state;tickFactory;constructor(e,t){this.renderCtx=e,this.state=t,this.tickFactory=Kn(this.state)}setState(e){this.state=w.prettyParse(Qs,e),this.tickFactory=Kn(e)}drawLine(e,t){const{lower2d:s}=this.renderCtx;s.moveTo(...r.xy.couple(e)),s.lineTo(...r.xy.couple(t))}drawTicks(e,t){let s=r.dimensions.ZERO;return e.forEach(o=>{const i=this.renderCtx.lower2d.textDimensions(o.label,yt);s=r.dimensions.max([s,i]),t(i,o)}),s}static START_BOUND=r.bounds.construct(-1,1);maybeDrawGrid(e,t,s){const{showGrid:o,gridColor:i}=this.state;if(o){const a=we.START_BOUND,l=r.bounds.construct(e-1,e+1),{lower2d:u}=this.renderCtx;u.beginPath(),u.strokeStyle=r.color.hex(i),t.forEach(c=>{r.bounds.contains(a,c.position)||r.bounds.contains(l,c.position)||this.drawLine(...s(c))}),u.stroke()}}setColor(e){const t=r.color.hex(e);this.renderCtx.lower2d.strokeStyle=t,this.renderCtx.lower2d.fillStyle=t,this.renderCtx.lower2d.font=this.state.font}}class ci extends we{render(e){const{lower2d:t}=this.renderCtx,{plot:s,position:o}=e,{width:i,height:a}=r.box.dims(s),l=this.tickFactory.create({...e,size:i});t.beginPath(),this.setColor(this.state.color),this.drawLine(o,r.xy.translate(o,"x",i));const u=this.drawTicks(l,(c,d)=>{this.drawLine(r.xy.translateX(o,d.position),r.xy.translate(o,{x:d.position,y:G})),t.fillText(d.label,o.x+d.position-c.width/2,o.y+G+c.height+rt,void 0,yt)});return t.stroke(),this.maybeDrawGrid(i,l,c=>[r.xy.translate(o,"x",c.position),r.xy.translate(o,{x:c.position,y:-a})]),{size:u.height+G+rt}}}class ui extends we{render(e){const{lower2d:t}=this.renderCtx,{plot:s}=e,{width:o,height:i}=r.box.dims(s),a=r.xy.translate(e.position,"y",e.size),l=this.tickFactory.create({...e,size:o});t.beginPath(),this.setColor(this.state.color),this.drawLine(a,r.xy.translate(a,"x",o));const u=this.drawTicks(l,(c,d)=>{this.drawLine(r.xy.translateX(a,d.position),r.xy.translate(a,{x:d.position,y:-G})),t.fillText(d.label,a.x+d.position-c.width/2,a.y-G-c.height-rt,void 0,yt)});return t.stroke(),this.maybeDrawGrid(o,l,c=>[r.xy.translate(a,"x",c.position),r.xy.translate(a,{x:c.position,y:i})]),{size:u.height+G}}}class $u extends we{render(e){const{lower2d:t}=this.renderCtx,{plot:s,position:o}=e,{height:i,width:a}=r.box.dims(s),l=r.xy.translate(o,"x",e.size),u=this.tickFactory.create({...e,size:i});t.beginPath(),this.setColor(this.state.color),this.drawLine(l,r.xy.translate(l,"y",i));const c=this.drawTicks(u,(d,f)=>{this.drawLine(r.xy.translateY(l,f.position),r.xy.translate(l,{x:-G,y:f.position})),t.fillText(f.label,l.x-d.width-G*2,l.y+f.position+d.height/2,void 0,yt)});return t.stroke(),this.maybeDrawGrid(i,u,d=>[r.xy.translate(l,"y",d.position),r.xy.translate(l,{x:a,y:d.position})]),{size:c.width+G*2}}}class hi extends we{render(e){const{lower2d:t}=this.renderCtx,{plot:s,position:o}=e,{height:i,width:a}=r.box.dims(s),l=this.tickFactory.create({...e,size:i});t.beginPath(),this.setColor(this.state.color),this.drawLine(o,r.xy.translateY(o,i));const u=this.drawTicks(l,(c,d)=>{this.drawLine(r.xy.translateY(o,d.position),r.xy.translate(o,{x:G,y:d.position})),t.fillText(d.label,o.x+G+rt,o.y+d.position+c.height/2,void 0,yt)});return t.stroke(),this.maybeDrawGrid(i,l,c=>[r.xy.translateY(o,c.position),r.xy.translate(o,{x:-a,y:c.position})]),{size:u.width+G+rt}}}const di=h.z.object({key:h.z.string(),size:h.z.number(),order:h.z.number(),loc:r.location.outer});h.z.record(h.z.string(),di);const me=(n,e)=>Object.values(e).filter(({loc:t})=>t===n).sort((t,s)=>s.order-t.order),Hu=(n,e,t)=>{const s=e[n];if(s==null)return r.xy.ZERO;const o=r.location.construct(s.loc),i=me(o,e),a=r.location.construct(r.direction.swap(r.location.direction(o))),l=me(a,e),u=i.findIndex(({key:f})=>f===n),c=i.slice(0,u).reduce((f,{size:p})=>f+p,0),d=l.reduce((f,{size:p})=>f+p,0);switch(o){case"left":return r.xy.translate(r.box.topLeft(t),[c,d]);case"right":return r.xy.translate(r.box.topRight(t),[c-s.size,d]);case"top":return r.xy.translate(r.box.topLeft(t),[d,c]);default:return r.xy.translate(r.box.bottomLeft(t),[d,-c-s.size])}},qu=(n,e)=>{const t=me("left",n),s=me("right",n),o=me("top",n),i=me("bottom",n),a=t.reduce((d,{size:f})=>d+f,0),l=s.reduce((d,{size:f})=>d+f,0),u=o.reduce((d,{size:f})=>d+f,0),c=i.reduce((d,{size:f})=>d+f,0);return r.box.construct(r.xy.translate(r.box.topLeft(e),{x:a,y:u}),r.box.width(e)-a-l,r.box.height(e)-u-c)},xt=Qs.extend({axisKey:h.z.string().optional(),bounds:r.bounds.bounds.optional(),autoBounds:h.z.object({lower:h.z.boolean().default(!0),upper:h.z.boolean().default(!0)}).or(h.z.boolean().default(!0)),autoBoundPadding:h.z.number().optional(),autoBoundUpdateInterval:r.TimeSpan.z.default(r.TimeSpan.seconds(10)),size:h.z.number().default(0),label:h.z.string().default(""),labelSize:h.z.number().default(0)}).partial({color:!0,font:!0,gridColor:!0}),ju=2,Wu=7,fi=(n,e)=>r.bounds.contains({lower:n-Wu,upper:n+ju},e),Vu=r.bounds.DECIMAL,Ar=r.TimeStamp.now(),Xu={lower:Number(Ar.valueOf()),upper:Number(Ar.add(r.TimeSpan.HOUR).valueOf())},pi=n=>n==="linear"?Vu:Xu,Gu=(n,e=.1,t)=>{const s=r.bounds.max(n.filter(r.bounds.isFinite));if(!r.bounds.isFinite(s))return pi(t);const{lower:o,upper:i}=s;if(i===o)return{lower:o-1,upper:i+1};const a=(i-o)*e;return{lower:o-a,upper:i+a}},Ku=.01,Qu=.1;class mi extends w.Composite{afterUpdate(e){const{internal:t}=this,{location:s,autoBoundUpdateInterval:o}=this.state;t.render=I.Context.use(e);const i=w.use(e),a=r.direction.construct(s);this.state.autoBoundPadding??=a==="x"?Qu:Ku,t.base=li(s,t.render,{color:i.colors.gray.l10,font:Je.fontString(i,{level:"small",code:!0}),gridColor:i.colors.gray.l1,...this.state}),ie(e,"layout"),t.updateBounds??=r.throttle(l=>this.setState(u=>({...u,bounds:l})),o.milliseconds)}afterDelete(e){ie(e,"layout")}renderAxis(e,t){if(!e.canvases.includes("lower2d"))return;const{base:s}=this.internal,{grid:o,container:i}=e,a=Hu(`${this.type}-${this.key}`,o,i),l={...e,position:a,decimalToDataScale:t,size:this.state.size+this.state.labelSize},{size:u}=s.render(l);fi(this.state.size,u)||this.setState(c=>({...c,size:u}))}iBounds(e,t){if(e&&this.internal.boundSnapshot!=null)return[this.internal.boundSnapshot,null];const{lower:s,upper:o}=gi(this.state.autoBounds);if(!s&&!o&&this.state.bounds!=null)return this.internal.boundSnapshot=this.state.bounds,[this.state.bounds,null];const i=c=>({upper:o||this.state.bounds==null?c.upper:this.state.bounds.upper,lower:s||this.state.bounds==null?c.lower:this.state.bounds.lower});let a,l=null;try{const c=t();a=Gu(c,this.state.autoBoundPadding,this.state.type)}catch(c){a=pi(this.state.type),l=c}const u=i(a);return this.internal.boundSnapshot=u,(this.state.bounds==null||s&&this.state.bounds.lower!==u.lower||o&&this.state.bounds.upper!==u.upper)&&this.internal.updateBounds?.(u),[u,l]}dataToDecimalScale(e,t,s){const[o,i]=this.iBounds(e,t),a=r.direction.swap(r.direction.construct(this.state.location));return[r.scale.Scale.scale(o).scale(1).translate(-r.box.root(s)[a]).magnify(1/r.box.dim(s,a)),i]}}const gi=n=>typeof n=="boolean"?{lower:n,upper:n}:{lower:n?.lower??!0,upper:n?.upper??!0};class Ee{canvas;theme;constructor(e,t){this.canvas=e,this.theme=t}rule({direction:e,region:t,position:s,...o}){return e==="x"?this.line({start:r.xy.construct(r.box.left(t),s),end:r.xy.construct(r.box.right(t),s),...o}):this.line({start:r.xy.construct(s,r.box.top(t)),end:r.xy.construct(s,r.box.bottom(t)),...o})}line({stroke:e,lineWidth:t,lineDash:s,start:o,end:i}){const a=this.canvas;a.strokeStyle=r.color.hex(e),a.lineWidth=t,a.setLineDash([s]),a.beginPath(),a.moveTo(...r.xy.couple(o)),a.lineTo(...r.xy.couple(i)),a.stroke()}circle({fill:e,stroke:t,strokeWidth:s,lineDash:o,radius:i,position:a,angle:l,lineCap:u}){const c=this.canvas;c.beginPath();const d=l?.lower??0,f=l?.upper??2*Math.PI;if(t!=null&&typeof i=="object"){const{inner:p,outer:g}=i,T=(p+g)/2,y=g-p;c.arc(...r.xy.couple(a),T,d,f,!1),c.strokeStyle=r.color.hex(t),c.lineWidth=s??y,u&&(c.lineCap=u),o!=null&&c.setLineDash([o]),c.stroke(),o!=null&&c.setLineDash([])}else if(t!=null&&typeof i=="number")c.arc(...r.xy.couple(a),i,d,f,!1),c.strokeStyle=r.color.hex(t),c.lineWidth=s??1,u&&(c.lineCap=u),o!=null&&c.setLineDash([o]),c.stroke(),o!=null&&c.setLineDash([]);else if(e!=null)if(c.fillStyle=r.color.hex(e),typeof i=="number")c.arc(...r.xy.couple(a),i,d,f),c.fill();else{const{inner:p,outer:g}=i;c.arc(...r.xy.couple(a),g,d,f,!1);const T=a.x+p*Math.cos(f),y=a.y+p*Math.sin(f);c.lineTo(T,y),c.arc(...r.xy.couple(a),p,f,d,!0),c.closePath(),c.fill()}}resolveColor(e,t){return e==null?t==null?this.theme.colors.text:this.resolveColor(t):typeof e=="function"?e(this.theme):r.color.construct(e)}border({region:e,color:t,width:s,radius:o,location:i}){const a=this.canvas;a.strokeStyle=r.color.hex(this.resolveColor(t,this.theme.colors.border)),a.lineWidth=s??this.theme.sizes.border.width,o??=this.theme.sizes.border.radius,i==null||i===!0?o>0?(a.roundRect(...r.xy.couple(r.box.topLeft(e)),...r.xy.couple(r.box.dims(e)),o),a.stroke()):(a.rect(...r.xy.couple(r.box.topLeft(e)),...r.xy.couple(r.box.dims(e))),a.stroke()):r.array.toArray(i).forEach(l=>{const[u,c]=r.box.edgePoints(e,l);a.beginPath(),a.moveTo(...r.xy.couple(u)),a.lineTo(...r.xy.couple(c)),a.stroke()})}container({region:e,bordered:t=!0,rounded:s=!0,borderColor:o,borderRadius:i,borderWidth:a,backgroundColor:l}){i??=this.theme.sizes.border.radius,a??=1;const u=this.canvas;u.fillStyle=r.color.hex(this.resolveColor(l,this.theme.colors.gray.l1)),u.strokeStyle=r.color.hex(this.resolveColor(o,this.theme.colors.border)),u.setLineDash([]),u.lineWidth=1,u.beginPath(),s?u.roundRect(...r.xy.couple(r.box.topLeft(e)),...r.xy.couple(r.box.dims(e)),i):u.rect(...r.xy.couple(r.box.topLeft(e)),...r.xy.couple(r.box.dims(e))),u.fill(),t&&this.border({region:e,color:o,radius:i,width:a,location:t})}textContainer(e){const[t,s]=this.spacedTextDrawF(e);t.width+=12,t.height+=12;const{root:o=r.location.TOP_LEFT,offset:i=r.xy.ZERO}=e,a={...e.position};o.x==="right"?a.x-=t.width+i.x:a.x+=i.x,o.y==="bottom"?a.y-=t.height+i.y:a.y+=i.y,this.container({region:r.box.construct(a,t.width,t.height),...e}),this.canvas.filter="none",s(r.xy.translate(a,[6,6]))}spacedTextDrawF({text:e,direction:t,spacing:s=1,level:o="p"}){const i=Je.fontString(this.theme,{level:o}),a=e.map(c=>sr.dimensions(c,i,this.canvas)),l=this.theme.sizes.base*s,u=Math.max(...a.map(c=>c[r.direction.dimension(t)]))+l;return[{[r.direction.dimension(r.direction.swap(t))]:Math.max(...a.map(c=>c[r.direction.dimension(r.direction.swap(t))])),[r.direction.dimension(t)]:u*e.length-l},c=>{const d=Je.fontString(this.theme,{level:o});this.canvas.font=d,this.canvas.fillStyle=r.color.hex(this.theme.colors.text),this.canvas.textBaseline="top",this.canvas.textAlign="start",e.forEach((f,p)=>{this.canvas.fillText(f,c.x,c.y+u*p)})}]}list({length:e,itemHeight:t,width:s,spacing:o=0,position:i,draw:a,root:l=r.location.TOP_LEFT,offset:u=r.xy.ZERO,padding:c=r.xy.ZERO}){const d=e*t+c.y*2+o*(e-1),f=s+c.x*2,p={...i};l.x==="right"?p.x-=s+u.x*2:p.x+=u.x,l.y==="top"?p.y-=d+u.y*2:p.y+=u.y,this.container({region:r.box.construct(p,{width:f,height:d}),backgroundColor:g=>g.colors.gray.l1});for(let g=0;g<e;g++){const T=r.box.construct(r.xy.construct(p.x+c.x,p.y+g*t+c.y+o*g),s,t);a(g,T)}}drawTextInCenter({box:e,text:t,level:s}){const o=sr.dimensions(t,this.canvas.font,this.canvas),i=r.box.positionInCenter(r.box.construct(r.xy.ZERO,o),e);return this.text({text:t,position:r.box.topLeft(i),level:s})}text({text:e,position:t,level:s="p",weight:o,shade:i,maxWidth:a,code:l,justify:u="left",align:c="top",useAtlas:d,color:f}){this.canvas.font=Je.fontString(this.theme,{level:s,weight:o,code:l}),f!=null?this.canvas.fillStyle=r.color.hex(this.resolveColor(f)):i==null?this.canvas.fillStyle=r.color.hex(this.theme.colors.text):this.canvas.fillStyle=r.color.hex(this.theme.colors.gray[`l${i}`]),this.canvas.textAlign=u,this.canvas.textBaseline=c;let p;a!=null&&(p=this.canvas.scissor(r.box.construct(t,a,1e3))),this.canvas.fillText(e,t.x,t.y,void 0,{useAtlas:d}),p?.()}}const Js=h.z.object({position:h.z.number().optional(),pixelPosition:h.z.number().optional(),dragging:h.z.boolean(),lineWidth:h.z.number().default(1),lineDash:h.z.number().default(20),color:r.color.colorZ}),Ju=3;class ot extends w.Leaf{static TYPE="Rule";schema=Js;lastUpdateRef=null;afterUpdate(e){this.internal.renderCtx=I.Context.use(e);const t=w.use(e);this.internal.draw=new Ee(this.internal.renderCtx.upper2d,t),ie(e,"tool")}afterDelete(e){ie(e,"tool")}updatePositions({decimalToDataScale:e,plot:t}){const s=this.state.dragging,o=this.prevState.dragging&&!s;if((s||o)&&this.state.pixelPosition!=null){if(this.lastUpdateRef??=this.state.pixelPosition,Math.abs(this.state.pixelPosition-this.lastUpdateRef)<Ju&&!o)return this.state.pixelPosition;this.lastUpdateRef=this.state.pixelPosition;const l=e.pos(this.state.pixelPosition/r.box.height(t));return this.setState(u=>({...u,position:l})),this.state.pixelPosition}if(this.state.position==null){const a=e.pos(.5);this.setState(l=>({...l,position:a}))}const i=e.reverse().pos(this.state.position)*r.box.height(t);if(!isNaN(i)){if(this.state.pixelPosition!=null&&Math.abs(i-this.state.pixelPosition)<1)return this.state.pixelPosition;this.setState(a=>({...a,pixelPosition:i}))}return i}render(e){if(this.deleted)return;const{renderCtx:t}=this.internal,{location:s,plot:o}=e,i=r.location.direction(s),{upper2d:a}=t,l=this.internal.draw,u=this.updatePositions(e)+r.box.top(e.plot);l.rule({stroke:this.state.color,lineWidth:this.state.lineWidth,lineDash:this.state.lineDash,direction:i,region:o,position:u}),a.fillStyle=r.color.hex(this.state.color),a.lineJoin="round",a.lineWidth=3.5,a.lineCap="round",a.beginPath();const c=4;if(s==="left"){const d=r.box.left(o)-1;a.moveTo(d,u),a.lineTo(d-c,u-c),a.lineTo(d-c,u+c)}else s==="right"&&(a.moveTo(r.box.right(o),u),a.lineTo(r.box.right(o)+c,u-c),a.lineTo(r.box.right(o)+c,u+c));a.closePath(),a.stroke()}}const yi={[ot.TYPE]:ot},eh=Object.freeze(Object.defineProperty({__proto__:null,REGISTRY:yi,Rule:ot,ruleStateZ:Js},Symbol.toStringTag,{value:"Module"})),th=xt.extend({location:r.location.x.default("left")}),Ir=2,nh=n=>r.box.signedWidth(n)<Ir||r.box.signedHeight(n)<Ir;class Qt extends mi{static TYPE="YAxis";schema=xt;xBounds(){return r.bounds.max(this.lines.map(e=>e.xBounds()).filter(e=>r.bounds.isFinite(e)))}bounds(e){const[t,s]=this.iBounds(e,this.dataBounds.bind(this));if(s!=null)throw s;return t}render(e){if(this.deleted)return;const[t,s]=this.dataToDecimalScale(e.hold,this.dataBounds.bind(this),e.viewport),o=t.invert().reverse();if(this.renderAxis(e,o),this.renderLines(e,t),this.renderRules(e,o),s!=null)throw s}renderLines({xDataToDecimalScale:e,plot:t,canvases:s,exposure:o},i){if(!s.includes("gl")||nh(t))return;const a={region:t,dataToDecimalScale:new r.scale.XY(e,i),exposure:o};this.lines.forEach(l=>l.render(a))}renderRules({container:e,plot:t,canvases:s},o){if(!s.includes("upper2d"))return;const{location:i}=this.state,{render:a}=this.internal,l=r.box.construct(r.box.left(e),r.box.top(t),r.box.width(e),r.box.height(t)),u=a.scissor(l,r.xy.ZERO,["upper2d"]),c={container:e,plot:t,decimalToDataScale:o,location:i};this.rules.map(d=>d.render(c)),u()}findByXValue({xDataToDecimalScale:e,plot:t,viewport:s,hold:o,exposure:i},a){const[l,u]=this.dataToDecimalScale(o,this.dataBounds.bind(this),s);if(u!=null)throw u;const c=new r.scale.XY(e,l),d={region:t,dataToDecimalScale:c,exposure:i};return this.lines.map(f=>({...f.findByXValue(d,a),units:this.state.label}))}dataBounds(){return this.lines.map(e=>e.yBounds())}get lines(){return this.childrenOfType($t.TYPE)}get rules(){return this.childrenOfType(ot.TYPE)}}const sh=h.z.object({start:r.TimeStamp.z,end:r.TimeStamp.z});class zr extends w.Leaf{static TYPE="range-annotation";schema=sh;afterUpdate(e){this.internal.render=I.Context.use(e),this.internal.draw=new Ee(this.internal.render.upper2d,w.use(e))}}const rh=x.ranger.payloadZ.extend({viewport:r.bounds.bounds}),xi=h.z.object({cursor:r.xy.xy.or(h.z.null()),hovered:rh.or(h.z.null()),count:h.z.number()});class Jt extends w.Leaf{static TYPE="range-provider";schema=xi;fetchedInitial=r.TimeRange.ZERO;afterUpdate(e){const{internal:t}=this;t.render=I.Context.use(e),t.draw=new Ee(t.render.upper2d,w.use(e)),t.requestRender=an(e),t.runAsync=w.useErrorHandler(e),t.ranges??=new Map;const s=He(e);if(t.requestRender("tool"),s==null)return;t.client=s;const o=Ki(e,this.key);t.removeListener?.();const i=o.ranges.onSet(l=>{t.client!=null&&(r.color.isCrude(l.color)&&t.ranges.set(l.key,t.client.ranges.sugarOne(l)),this.setState(u=>({...u,count:t.ranges.size})),t.requestRender("tool"))}),a=o.ranges.onDelete(async l=>{t.ranges.delete(l),this.setState(u=>({...u,count:t.ranges.size})),t.requestRender("tool")});t.removeListener=()=>{i(),a()}}fetchInitial(e){const{internal:t}=this,{client:s,runAsync:o}=t;s==null||this.fetchedInitial.equals(e,r.TimeSpan.minutes(1))||(this.fetchedInitial=e,o(async()=>{(await s.ranges.retrieve(e)).forEach(a=>{r.color.isCrude(a.color)&&t.ranges.set(a.key,a)}),this.setState(a=>({...a,count:t.ranges.size}))},"failed to fetch initial ranges"))}render(e){const{dataToDecimalScale:t,region:s,viewport:o,timeRange:i}=e;this.fetchInitial(i);const{draw:a,ranges:l}=this.internal,u=t.scale(r.box.xBounds(s)),c=this.state.cursor==null?null:this.state.cursor.x;let d=null;const f=a.canvas.scissor(r.box.construct({x:r.box.left(s),y:r.box.top(s)-35},{x:r.box.right(s),y:r.box.bottom(s)}));l.forEach(p=>{const g=r.color.colorZ.safeParse(p.color);if(!g.success)return;const T=g.data;let y=u.pos(Number(p.timeRange.start.valueOf()));const v=u.pos(Number(p.timeRange.end.valueOf()));if(v<r.box.left(s)||y>r.box.right(s))return;y=r.clamp(y,r.box.left(s)-2,r.box.right(s)-1);let R=!1;c!=null&&(R=r.bounds.contains({lower:y,upper:v},c)),R&&(d={key:p.key,parent:p.parent,name:p.name,color:p.color,labels:p.labels,timeRange:p.timeRange,viewport:{lower:t.scale(r.box.xBounds(o)).pos(Number(p.timeRange.start.valueOf())),upper:t.scale(r.box.xBounds(o)).pos(Number(p.timeRange.end.valueOf()))}}),a.container({region:r.box.construct({x:y,y:r.box.top(s)-1},{x:v,y:r.box.bottom(s)-1}),backgroundColor:r.color.setAlpha(T,.2),bordered:!1});const L=r.box.construct({x:y+1,y:r.box.top(s)-34},{x:v-1,y:r.box.top(s)-12});a.container({region:L,backgroundColor:r.box.width(L)<20?r.color.setAlpha(T,.4):k=>R?k.colors.gray.l2:k.colors.gray.l0,bordered:!0,borderWidth:1,borderRadius:2,borderColor:r.color.setAlpha(T,.8)}),a.text({text:p.name,position:{x:y+8,y:r.box.top(s)-30},level:"small",shade:10,weight:500,maxWidth:v-y-16})}),f(),d!=null?this.setState(p=>({...p,hovered:d})):this.state.hovered&&this.setState(p=>({...p,hovered:null}))}}const oh={[zr.TYPE]:zr,[Jt.TYPE]:Jt},ih=xt;class en extends mi{static TYPE="XAxis";schema=xt;render(e){if(this.deleted)return;const[t,s]=this.dataToDecimalScale(e.hold,this.dataBounds.bind(this),e.viewport);if(this.renderAxis(e,t.reverse()),this.renderYAxes(e,t),this.renderRanges(e,t),s!=null)throw s}findByXDecimal(e,t){const[s,o]=this.dataToDecimalScale(e.hold,this.dataBounds.bind(this),e.viewport);if(o!=null)throw o;return this.findByXValue(e,s.reverse().pos(t))}findByXValue(e,t){const[s,o]=this.dataToDecimalScale(e.hold,this.dataBounds.bind(this),e.viewport);if(o!=null)throw o;const i={...e,xDataToDecimalScale:s};return this.yAxes.map(a=>a.findByXValue(i,t)).flat()}renderYAxes(e,t){const s={...e,xDataToDecimalScale:t};this.yAxes.forEach(o=>o.render(s))}get yAxes(){return this.childrenOfType(Qt.TYPE)}get ranges(){return this.childrenOfType(Jt.TYPE)}bounds(e){const[t,s]=this.iBounds(e,this.dataBounds.bind(this));if(s!=null)throw s;return t}renderRanges(e,t){const s=this.bounds(e.hold),o=r.bounds.min([s,r.TimeRange.MAX.numericBounds]),i=new r.TimeRange(o.lower,o.upper);this.ranges.forEach(a=>a.render({dataToDecimalScale:t,region:e.plot,viewport:e.viewport,timeRange:i}))}dataBounds(){return this.yAxes.map(e=>e.xBounds())}}const ah=r.xy.construct(12),lh=3,ch=14,uh=r.xy.construct(6),er=h.z.object({position:r.xy.xy.or(h.z.null()),textColor:r.color.colorZ.default(r.color.ZERO),backgroundColor:r.color.colorZ.default(r.color.ZERO),borderColor:r.color.colorZ.default(r.color.ZERO),ruleColor:r.color.colorZ.default(r.color.ZERO),ruleStrokeWidth:h.z.number().default(1),ruleStrokeDash:h.z.number().default(0)});class it extends w.Leaf{static TYPE="tooltip";schema=er;afterUpdate(e){const t=w.use(e);r.color.isZero(this.state.textColor)&&(this.state.textColor=t.colors.text),r.color.isZero(this.state.backgroundColor)&&(this.state.backgroundColor=t.colors.gray.l1),r.color.isZero(this.state.borderColor)&&(this.state.borderColor=t.colors.border),r.color.isZero(this.state.ruleColor)&&(this.state.ruleColor=t.colors.gray.l7),this.internal.dotColor=t.colors.text,this.internal.dotColorContrast=t.colors.textInverted,this.internal.render=I.Context.use(e),this.internal.draw=new Ee(this.internal.render.upper2d,t),ie(e,"tool")}afterDelete(e){ie(e,"tool")}render(e){if(this.deleted||this.state.position==null)return;const{region:t}=e,s=r.scale.XY.scale(r.box.DECIMAL).scale(t),o=r.scale.XY.scale(t).scale(r.box.DECIMAL),i=e.findByXDecimal(o.x.pos(this.state.position.x)),a=i.filter(y=>r.xy.isFinite(y.value)),{draw:l}=this.internal,u=a.reduce((y,v)=>y+v.position.x,0)/a.length,c=new r.TimeStamp(a.reduce((y,v)=>y+v.value.x,0)/a.length),d=s.x.pos(u);if(!r.bounds.contains(r.box.xBounds(t),d))return;l.rule({stroke:this.state.ruleColor,lineWidth:this.state.ruleStrokeWidth,lineDash:this.state.ruleStrokeDash,direction:"y",region:t,position:d}),a.forEach(y=>{const v=s.pos(y.position);l.circle({fill:r.color.setAlpha(y.color,.5),radius:8,position:v}),l.circle({fill:r.color.setAlpha(y.color,.8),radius:5,position:v}),l.circle({fill:r.color.pickByContrast(y.color,this.internal.dotColor,this.internal.dotColorContrast),radius:2,position:v})});const f=o.pos(this.state.position),p={...r.location.TOP_LEFT};f.x>.6&&(p.x="right"),f.y>.6&&(p.y="bottom");let g=i.reduce((y,v)=>Math.max(y,v.label?.length??0),0);const T=c.toString("preciseDate","local").length;T>g&&(g=T),l.list({root:p,offset:ah,length:a.length+1,padding:uh,itemHeight:ch,spacing:lh,width:g*7+48,position:this.state.position,draw:(y,v)=>{let R="",L="",k=this.state.textColor;if(y===0)R="Time",L=c.toString("preciseDate","local");else{const C=a[y-1];R=C.label??"",L=r.math.roundBySpan(C.value.y,C.bounds).toString(),k=C.color}l.text({position:r.box.topLeft(v),text:R,level:"small",weight:500,color:k}),l.text({position:r.xy.translateY(r.box.topRight(v),-1),text:L,level:"small",justify:"right",code:!0,shade:10})}})}}const bi={[it.TYPE]:it},hh=Object.freeze(Object.defineProperty({__proto__:null,REGISTRY:bi,Tooltip:it,tooltipStateZ:er},Symbol.toStringTag,{value:"Module"})),Si=h.z.enum(["one","two"]),tr=h.z.object({one:r.xy.xy.nullable(),two:r.xy.xy.nullable(),hover:r.xy.xy.nullable(),mode:Si.default("one"),color:h.z.union([r.color.colorZ,h.z.object({verticalLine:r.color.colorZ.default(r.color.ZERO),horizontalLine:r.color.colorZ.default(r.color.ZERO),obliqueLine:r.color.colorZ.default(r.color.ZERO)})]).optional().default(r.color.ZERO),strokeWidth:h.z.number().default(1),strokeDash:h.z.number().default(2)}),dh=n=>n==="one"?"1":"2",fh=n=>n.colors.error.z,ph=n=>n.colors.secondary.z,mh=n=>n.colors.gray.l9,Xe=6,Ge=14,Ke=8,Et=8,Ct=3,gh=9,yh=8,xh=2,bh=2,Sh=8,Th=5,vh=2,wh=.5,Eh=.8,Rt=50,Pt=80,Ch=30,Rh=30,Ph=10,Lh=40,kh=100,_h=30,Re=15,Yr=8,Oh=10;class at extends w.Leaf{static TYPE="measure";schema=tr;afterUpdate(e){const t=I.Context.use(e);this.internal.theme=w.use(e),this.internal.renderCtx=t,this.internal.draw=new Ee(t.upper2d,this.internal.theme),ie(e,"tool"),this.internal.dotColor=this.internal.theme.colors.text,this.internal.dotColorContrast=this.internal.theme.colors.textInverted}afterDelete(e){ie(e,"layout")}get verticalLineColor(){return r.color.isColor(this.state.color)?r.color.isZero(this.state.color)?this.internal.theme.colors.gray.l8:this.state.color:r.color.isZero(this.state.color.verticalLine)?this.internal.theme.colors.gray.l8:this.state.color.verticalLine}get horizontalLineColor(){return r.color.isColor(this.state.color)?r.color.isZero(this.state.color)?this.internal.theme.colors.gray.l8:this.state.color:r.color.isZero(this.state.color.horizontalLine)?this.internal.theme.colors.gray.l8:this.state.color.horizontalLine}get obliqueLineColor(){return r.color.isColor(this.state.color)?r.color.isZero(this.state.color)?this.internal.theme.colors.gray.l8:this.state.color:r.color.isZero(this.state.color.obliqueLine)?this.internal.theme.colors.gray.l8:this.state.color.obliqueLine}findPoint(e,t,s,o,i){const a=o!=null&&!r.xy.equals(t,o);if(s!=null&&!a){const c=e.findByXValue(s.x).filter(d=>Number.isFinite(d.value.x)&&Number.isFinite(d.value.y));return c.length>0?c.sort((d,f)=>r.xy.distance(s,d.value)-r.xy.distance(s,f.value))[0]:null}const l=i.pos(t),u=e.findByXDecimal(l.x).filter(c=>Number.isFinite(c.value.x)&&Number.isFinite(c.value.y));return u.length===0?null:u.sort((c,d)=>r.xy.distance(l,c.position)-r.xy.distance(l,d.position))[0]}find(e){const{one:t,two:s}=this.state;if(t==null||s==null)return null;const{dataOne:o,dataTwo:i,clickOne:a,clickTwo:l}=this.internal,u=r.scale.XY.scale(e.region).scale(r.box.DECIMAL),c=this.findPoint(e,t,o,a,u);if(c==null)return null;(a==null||!r.xy.equals(t,a))&&(this.internal.dataOne={...c.value},this.internal.clickOne={...t});const d=this.findPoint(e,s,i,l,u);return d==null?null:((l==null||!r.xy.equals(s,l))&&(this.internal.dataTwo={...d.value},this.internal.clickTwo={...s}),[c,d])}drawLabelValue(e,t,s,o){const{draw:i}=this.internal,a=r.xy.construct(Xe),l=e.length*Ke,u=t.length*Et,c=l+u+a.x*Ct,d=Ge+a.y*2,f=r.box.construct(s,c,d);i.container({region:f,backgroundColor:p=>p.colors.gray.l1}),i.text({text:e,position:r.xy.translate(r.box.topLeft(f),a),level:"small",weight:500,color:o(this.internal.theme)}),i.text({text:t,position:r.xy.translate(r.box.topRight(f),[-a.x-1,a.y-1]),level:"small",justify:"right",code:!0,shade:10})}drawCombinedDeltaLabel(e,t,s,o,i,a){const{draw:l,theme:u}=this.internal,c=r.xy.construct(Xe),d=Ke*5,f=Math.max(t.length,s.length,o.length),p=d+f*Et+c.x*Ct,g=Ge,T=g*3+c.y*2;let y;if(a){const v=r.xy.translate(e,[-p/2,-T/2]);y=r.box.construct(v,p,T)}else if(y=r.box.construct(e,p,T),r.box.right(y)>r.box.right(i)){const v=r.xy.translateX(e,-p-Pt*2);y=r.box.construct(v,p,T)}l.container({region:y,backgroundColor:v=>v.colors.gray.l1}),this.drawPointLabelRow({region:y,label:"ΔX",value:t,labelColor:u.colors.error.z,yOffset:0,leftOffset:0}),this.drawPointLabelRow({region:y,label:"ΔY",value:s,labelColor:u.colors.secondary.z,yOffset:g,leftOffset:0}),this.drawPointLabelRow({region:y,label:"Slope",value:o,labelColor:u.colors.gray.l9,yOffset:g*2,leftOffset:0})}drawPointLabelRow(e){const{region:t,label:s,value:o,labelColor:i,yOffset:a,leftOffset:l}=e,{draw:u}=this.internal,c=r.xy.construct(Xe);u.text({text:s,position:r.xy.translate(r.box.topLeft(t),[c.x+l,c.y+a]),level:"small",weight:500,color:i}),u.text({text:o,position:r.xy.translate(r.box.topRight(t),[-c.x-1,c.y+a-1]),level:"small",justify:"right",code:!0,shade:10})}drawPointLabel(e){const{pointNumber:t,position:s,value:o,units:i,bounds:a,toTop:l,viewRegion:u,xDist:c}=e,{draw:d,theme:f}=this.internal,p=new r.TimeStamp(o.x),g=p.toString(p.formatBySpan(c),"local"),T=`${r.math.roundBySpan(o.y,a)} ${i??""}`,y=`${t}`,v=y.length*Ke,R=r.xy.construct(Xe),L=Ke,k=Math.max(g.length,T.length),C=v+Yr+L+k*Et+R.x*Ct,Z=Ge,b=Z*2+R.y*2;let M=l?-(b+Re):Re,A=r.box.construct(r.xy.translate(s,[-C/2,M]),C,b);(l&&r.box.top(A)<r.box.top(u)||!l&&r.box.bottom(A)>r.box.bottom(u))&&(M=l?Re:-(b+Re),A=r.box.construct(r.xy.translate(s,[-C/2,M]),C,b)),d.container({region:A,backgroundColor:K=>K.colors.gray.l1}),d.text({text:y,position:r.xy.translate(r.box.topLeft(A),[R.x,R.y]),level:"small",weight:500,color:f.colors.gray.l9});const V=v+Yr;this.drawPointLabelRow({region:A,label:"X",value:g,labelColor:f.colors.error.z,yOffset:0,leftOffset:V}),this.drawPointLabelRow({region:A,label:"Y",value:T,labelColor:f.colors.secondary.z,yOffset:Z,leftOffset:V})}drawPointMarker(e,t){const{draw:s}=this.internal;s.circle({fill:r.color.setAlpha(t,wh),radius:Sh,position:e}),s.circle({fill:r.color.setAlpha(t,Eh),radius:Th,position:e}),s.circle({fill:r.color.pickByContrast(t,this.internal.dotColor,this.internal.dotColorContrast),radius:vh,position:e})}calculateYLabelPosition(e,t,s){return t?r.xy.translateX(e,Ch):s?r.xy.translateX(e,Rh):e}calculateXLabelPosition(e,t,s){return t?r.xy.translateY(e,Lh):s?r.xy.translateY(e,Ph):e}calculateSlopeLabelPosition(e){const{basePos:t,yLabelPos:s,isVeryClose:o,isHorizontal:i,xPixelDist:a,yPixelDist:l}=e;return o?r.xy.translateX(t,Pt):i?r.xy.translateY(t,-35):Math.abs(t.x-s.x)<kh&&Math.abs(t.y-s.y)<_h?a<l?r.xy.translateY(t,-35):r.xy.translateX(t,Pt):t}renderHover(e){if(this.state.hover==null)return;const t=this.state.hover,s=r.scale.XY.scale(e.region).scale(r.box.DECIMAL),o=s.pos(t),i=e.findByXDecimal(s.pos(t).x);if(i.length===0)return;const a=i.sort((c,d)=>r.xy.distance(o,c.position)-r.xy.distance(o,d.position))[0],{draw:l}=this.internal,u=s.reverse().pos(a.position);l.circle({stroke:r.color.setAlpha(a.color,1),strokeWidth:xh,lineDash:bh,radius:gh,position:u}),l.circle({fill:this.internal.theme.colors.gray.l3,radius:yh,position:u}),l.text({text:dh(this.state.mode),position:u,level:"small",align:"middle",justify:"center"})}render(e){if(this.deleted)return;this.renderHover(e);const t=this.find(e);if(t==null)return;const[s,o]=t,{draw:i}=this.internal,{strokeDash:a,strokeWidth:l}=this.state,u=r.scale.XY.scale(r.box.DECIMAL).scale(e.region),c=u.pos(s.position),d=u.pos(o.position),f=Math.abs(s.value.x-o.value.x),p=o.value.y-s.value.y,g=Math.abs(p);if(!Number.isFinite(f)||!Number.isFinite(g))return;const T=new r.TimeSpan(f),y=p/T.seconds,v=Math.abs(c.x-d.x),R=Math.abs(c.y-d.y),L=R<Rt,k=v<Rt,C=v<Rt||R<Rt;i.line({start:r.xy.construct(c.x,c.y),end:r.xy.construct(c.x,d.y),stroke:this.verticalLineColor,lineDash:a,lineWidth:l}),i.line({start:r.xy.construct(c.x,d.y),end:r.xy.construct(d.x,d.y),stroke:this.horizontalLineColor,lineDash:a,lineWidth:l}),i.line({start:r.xy.construct(c.x,c.y),end:r.xy.construct(d.x,d.y),stroke:this.obliqueLineColor,lineDash:a,lineWidth:l}),this.drawPointMarker(c,s.color),this.drawPointMarker(d,o.color);const Z=`${r.math.roundBySpan(g,r.bounds.construct(g))} ${s.units??""}`,b=T.lessThan(r.TimeSpan.milliseconds(Oh))?r.TimeSpan.MICROSECOND:r.TimeSpan.MILLISECOND,M=T.truncate(b).toString();let A=r.math.roundBySpan(y,r.bounds.construct(Math.abs(y))).toString();if(s.units!=null&&s.units.length>0&&(A+=` ${s.units} / s`),C){const K=r.xy.construct((c.x+d.x)/2,(c.y+d.y)/2),ue=Ke*6,E=Math.max(M.length,Z.length,A.length),$=Xe,N=ue+E*Et+$*Ct,Q=Ge*3+$*2,de=r.box.construct(r.xy.translate(K,[-N/2,-Q/2]),N,Q),ne=c.y<d.y,J=150,se=Ge*2+$*2,H=ne?-55:Re,xn=r.box.construct(r.xy.translate(c,[-J/2,H]),J,se),bn=ne?Re:-55,Sn=r.box.construct(r.xy.translate(d,[-J/2,bn]),J,se),Tn=r.box.area(r.box.intersection(de,xn))>0,vn=r.box.area(r.box.intersection(de,Sn))>0,bt=!Tn&&!vn,wn=bt?K:r.xy.construct(Math.max(c.x,d.x)+Pt,(c.y+d.y)/2);this.drawCombinedDeltaLabel(wn,M,Z,A,e.region,bt)}else{const K=this.calculateYLabelPosition(r.xy.construct(c.x,(c.y+d.y)/2),C,k);this.drawLabelValue("ΔY",Z,K,ph);const ue=this.calculateXLabelPosition(r.xy.construct((c.x+d.x)/2,d.y),C,L);this.drawLabelValue("ΔX",M,r.xy.translateX(ue,-15),fh);const E=this.calculateSlopeLabelPosition({basePos:r.xy.construct((c.x+d.x)/2,(c.y+d.y)/2),yLabelPos:K,isVeryClose:C,isHorizontal:L,xPixelDist:v,yPixelDist:R});this.drawLabelValue("Slope",A,E,mh)}const V=c.y<d.y;this.drawPointLabel({pointNumber:1,position:c,value:s.value,units:s.units??null,bounds:s.bounds,toTop:V,viewRegion:e.region,xDist:T}),this.drawPointLabel({pointNumber:2,position:d,value:o.value,units:o.units??null,bounds:o.bounds,toTop:!V,viewRegion:e.region,xDist:T})}}const Ti={[at.TYPE]:at},Mh=Object.freeze(Object.defineProperty({__proto__:null,Measure:at,REGISTRY:Ti,measureStateZ:tr,modeZ:Si},Symbol.toStringTag,{value:"Module"})),vi=h.z.object({container:r.box.box,viewport:r.box.box,hold:h.z.boolean().default(!1),grid:h.z.record(h.z.string(),di),visible:h.z.boolean().default(!0),clearOverScan:r.xy.crudeZ.default(r.xy.ZERO)}),Dh=h.z.record(h.z.string(),h.z.object({lower:h.z.number(),upper:h.z.number()})),wi={getBounds:h.z.function({input:h.z.tuple([]),output:Dh})},Ah=(n,e)=>{const t=r.box.width(n)*Math.sqrt(r.box.height(n)),s=r.box.width(e)*Math.sqrt(r.box.height(e));return t/s},Ih=["upper2d","lower2d","gl"],zh=["upper2d"];class Jn extends w.Composite{static TYPE="LinePlot";schema=vi;methods=wi;afterUpdate(e){this.internal.instrumentation=I.useInstrumentation(e,"lineplot"),this.internal.handleError=w.useErrorHandler(e),this.internal.renderCtx=I.Context.use(e),on(e,t=>{this.state.visible&&this.requestRender("low",t)}),!(!this.state.visible&&!this.prevState.visible)&&this.requestRender("high","layout")}afterDelete(e){this.internal.renderCtx=I.Context.use(e),this.requestRender("high","layout")}findByXDecimal(e){const t={...this.state,plot:this.calculatePlot(),exposure:this.exposure};return this.axes.flatMap(s=>s.findByXDecimal(t,e)).flat()}findByXValue(e){const t={...this.state,plot:this.calculatePlot(),exposure:this.exposure};return this.axes.flatMap(s=>s.findByXValue(t,e)).flat()}get axes(){return this.childrenOfType(en.TYPE)}get tooltips(){return this.childrenOfType(it.TYPE)}get measures(){return this.childrenOfType(at.TYPE)}get exposure(){return Ah(this.state.viewport,this.state.container)}renderAxes(e,t){const s={...this.state,plot:e,canvases:t,exposure:this.exposure};this.axes.forEach(o=>o.render(s))}renderTooltips(e,t){const s={findByXDecimal:this.findByXDecimal.bind(this),region:e,canvases:t};this.tooltips.forEach(o=>o.render(s))}getBounds(){const e={};return this.axes.forEach(t=>{const s=t.state.axisKey??t.key;e[s]=t.bounds(this.state.hold),t.yAxes.forEach(o=>{const i=o.state.axisKey??o.key;e[i]=o.bounds(this.state.hold)})}),e}renderMeasures(e){const t={findByXDecimal:this.findByXDecimal.bind(this),findByXValue:this.findByXValue.bind(this),region:e};this.measures.forEach(s=>s.render(t))}calculatePlot(){return qu(this.state.grid,this.state.container)}render(e){const{instrumentation:t,renderCtx:s,handleError:o}=this.internal;if(this.deleted){t.L.debug("deleted, skipping render",{key:this.key});return}if(!this.state.visible)return t.L.debug("not visible, skipping render",{key:this.key}),({canvases:d})=>s.erase(this.state.container,this.state.clearOverScan,...d);const i=this.calculatePlot();t.L.debug("rendering",{key:this.key,viewport:this.state.viewport,container:this.state.container,grid:this.state.grid,plot:i,canvases:e});const a=r.xy.construct(this.state.clearOverScan),l=s.scissor(this.state.container,a,e.filter(d=>d!=="gl")),u=s.scissor(i,r.xy.ZERO,e.filter(d=>d==="gl"));try{this.renderAxes(i,e),this.renderTooltips(i,e),this.renderMeasures(i)}catch(d){o(d,"failed to render line plot")}finally{l(),u()}t.L.debug("rendered",{key:this.key});const c=r.box.copy(this.state.container);return({canvases:d})=>s.erase(c,this.state.clearOverScan,...d)}requestRender(e,t){const{renderCtx:s}=this.internal;let o=Ih;t==="tool"&&(o=zh),s.loop.set({key:`${this.type}-${this.key}`,render:()=>this.render(o),priority:e,canvases:o})}}const Yh={[Jn.TYPE]:Jn,[en.TYPE]:en,[Qt.TYPE]:Qt},Ei=h.z.object({region:r.box.box,wheelPos:h.z.number(),scrolling:h.z.boolean(),empty:h.z.boolean(),visible:h.z.boolean(),telem:Mt.default(eo),font:ge.levelZ.default("p"),color:r.color.colorZ.default(r.color.ZERO),overshoot:r.xy.xy.default({x:0,y:0})}),Nh=.98,Qe="lower2d",Zh={offset:0n,offsetRef:0n,scrollRef:0};class lt extends w.Leaf{static TYPE="log";static z=Ei;schema=lt.z;values=new r.MultiSeries([]);scrollState=Zh;afterUpdate(e){const{internal:t}=this;t.render=I.Context.use(e),t.theme=w.use(e),r.color.isZero(this.state.color)?this.internal.textColor=t.theme.colors.gray.l11:t.textColor=this.state.color,t.telem=U(e,this.state.telem,t.telem);const{scrolling:s,wheelPos:o}=this.state;if(this.state.scrolling&&!this.prevState.scrolling){const u=this.values.alignmentBounds.upper-1n;this.scrollState={offset:u,offsetRef:u,scrollRef:this.state.wheelPos}}else if(s){const{scrollState:u,values:c}=this,d=Math.ceil((o-this.scrollState.scrollRef)/this.lineHeight);u.offset=this.values.traverseAlignment(u.offsetRef,-BigInt(d)),u.offset<c.alignmentBounds.lower+BigInt(this.visibleLineCount)&&(u.offset=c.alignmentBounds.lower,this.setState(f=>({...f,wheelPos:this.prevState.wheelPos}))),u.offset>=c.alignmentBounds.upper&&this.setState(f=>({...f,scrolling:!1}))}const[a,l]=this.internal.telem.value();this.values=l,this.checkEmpty(),t.stopListeningTelem?.(),t.stopListeningTelem=t.telem.onChange(()=>{const[u,c]=this.internal.telem.value();this.checkEmpty(),this.values=c,this.requestRender()}),!(!this.state.visible&&!this.prevState.visible)&&this.requestRender()}checkEmpty(){const e=this.values.length===0;e!==this.state.empty&&this.setState(t=>({...t,empty:e}))}afterDelete(){const{telem:e,render:t}=this.internal;e.cleanup?.(),t.erase(r.box.construct(this.state.region),r.xy.ZERO,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((r.box.height(this.state.region)-12)/this.lineHeight),this.values.length)}render(){const{render:e}=this.internal,t=this.state.region;if(r.box.areaIsZero(t))return;if(!this.state.visible)return()=>e.erase(t,r.xy.ZERO,Qe);let s;if(!this.state.scrolling)s=this.values.subIterator(this.values.length-this.visibleLineCount,this.values.length);else{const c=this.values.traverseAlignment(this.scrollState.offset,-BigInt(this.visibleLineCount));s=this.values.subAlignmentSpanIterator(c,this.visibleLineCount)}const o=this.state.region,i=e[Qe],a=new Ee(i,this.internal.theme),l=e.scissor(o,r.xy.ZERO,[Qe]);this.renderElements(a,s),this.renderScrollbar(a),l();const u=r.box.copy(this.state.region);return({canvases:c})=>e.erase(u,this.state.overshoot,...c)}renderScrollbar(e){const t=this.state.region,s=r.box.height(t)/this.totalHeight*r.box.height(t);if(s>=r.box.height(t)*Nh)return;let o=r.box.bottom(t)-s;this.state.scrolling&&(o-=Number(this.values.distance(this.values.alignmentBounds.upper,this.scrollState.offset))/this.values.length*r.box.height(t)),o<0&&(o=r.box.top(t)),e.container({region:r.box.construct({x:r.box.right(t)-6,y:o},{width:6,height:s}),bordered:!1,backgroundColor:i=>i.colors.gray.l6})}renderElements(e,t){const s=this.state.region;let o=0;for(const i of t){const a=this.values.dataType.equals(r.DataType.JSON)?JSON.stringify(i):i.toString();e.text({text:a,level:this.state.font,shade:11,position:r.xy.translate(r.box.topLeft(s),{x:6,y:o*this.lineHeight+6}),code:!0}),o++}}}const Uh={[lt.TYPE]:lt},Bh="roles",Fh={channel:x.access.role.SET_CHANNEL_NAME,schema:x.access.role.roleZ,onChange:({store:n,changed:e})=>{n.roles.set(e.key,e)}},$h={channel:x.access.role.DELETE_CHANNEL_NAME,schema:x.access.role.keyZ,onChange:({store:n,changed:e})=>n.roles.delete(e)},Hh={listeners:[Fh,$h]},qh="ranges",jh={channel:x.ranger.SET_CHANNEL_NAME,schema:x.ranger.payloadZ,onChange:async({store:n,changed:e,client:t})=>{const s=t.ranges.sugarOne(e),o=n.ranges.get(e.key);let i;o?.labels==null&&(i=await s.retrieveLabels());let a=null;o?.parent==null&&(a=await s.retrieveParent()),n.ranges.set(e.key,l=>t.ranges.sugarOne({...s.payload,labels:l?.labels??i,parent:l?.parent??a}))}},Wh={channel:x.ranger.DELETE_CHANNEL_NAME,schema:x.ranger.keyZ,onChange:({store:n,changed:e})=>n.ranges.delete(e)},Vh={equal:(n,e)=>r.deep.equal(n.payload,e.payload),listeners:[jh,Wh]},Ci=h.z.object({authority:r.control.authorityZ.optional(),valid:h.z.boolean().optional()}).default({authority:void 0,valid:!1}),Ri=h.z.object({triggered:h.z.boolean(),status:r.status.statusZ(Ci),sink:un.default(cn),source:Ls.default(Cs)});class es extends w.Leaf{static TYPE="Chip";schema=Ri;afterUpdate(e){const{internal:t}=this,{sink:s,source:o}=this.state;t.source=U(e,o,t.source),t.sink=qe(e,s,t.sink),this.state.triggered&&!this.prevState.triggered&&t.sink.set(this.state.status.details?.authority!==r.control.ABSOLUTE_AUTHORITY),this.updateEnabledState(),t.stopListening?.(),t.stopListening=t.source.onChange(()=>this.updateEnabledState())}updateEnabledState(){const e=this.internal.source.value();r.deep.equal(e,this.state.status)||this.setState(t=>({...t,status:e,triggered:!1}))}afterDelete(){this.internal.stopListening(),this.internal.source.cleanup?.(),this.internal.sink.cleanup?.()}render(){}}const Pi=h.z.object({}),Nr="control-state-provider",Li=x.control.stateZ.extend({subjectColor:r.color.colorZ});class ct extends w.Composite{static TYPE="StateProvider";schema=Pi;colors=new Map;colorOverrides=new Map;tracker;disconnectTrackerChange;obs=new r.observe.Observer;static use(e){return e.get(Nr)}afterUpdate(e){const{internal:t}=this;t.instrumentation=I.useInstrumentation(e,"control-state");const s=w.use(e);t.palette=s.colors.visualization.palettes.default,t.defaultColor=s.colors.gray.l8;const o=He(e);if(t.client!=null&&o===t.client)return;t.client=o,e.set(Nr,this),w.useErrorHandler(e)(async()=>{await this.maybeCloseTracker(),t.client!=null&&(this.internal.instrumentation.L.debug("starting state tracker"),await this.openTracker(t.client))},"failed to open control state tracker")}async maybeCloseTracker(){this.tracker!=null&&(this.internal.instrumentation.L.debug("stopping state tracker"),this.disconnectTrackerChange?.(),await this.tracker.close(),this.tracker=void 0)}afterDelete(e){w.useErrorHandler(e)(async()=>{await this.maybeCloseTracker()},"failed to close control state tracker")}onChange(e){return this.obs.onChange(e)}setColorOverrides(e){const t=Object.entries(e);if(!(t.length===this.colorOverrides.size&&t.every(([s,o])=>{const i=this.colorOverrides.get(s);return i!=null&&r.color.equals(i,o)}))){this.colorOverrides.clear();for(const[s,o]of t)this.colorOverrides.set(s,r.color.construct(o));this.obs.notify([])}}get(e){return Array.isArray(e)?r.unique.unique(e).map(t=>this.getOne(t)).filter(t=>t!=null):this.getOne(e)}getOne(e){if(this.tracker==null)return;const t=this.tracker.states.get(e);if(t!=null)return{...t,subjectColor:this.colorOverrides.get(t.subject.key)??this.colors.get(t.subject.key)??this.internal.defaultColor}}async openTracker(e){const{internal:t}=this,{instrumentation:s}=t;try{this.tracker=await e.control.openStateTracker()}catch{s.L.error("failed to open state tracker");return}this.disconnectTrackerChange?.(),this.disconnectTrackerChange=this.tracker.onChange(o=>{if(s.L.debug("transfer",{transfers:o.map(i=>x.control.transferString(i))}),this.tracker==null)throw new x.UnexpectedError("tracker is null inside it's own onChange callback!");this.updateColors(this.tracker),this.obs.notify(o)})}updateColors(e){const t=e.subjects(),s=t.map(a=>a.key),o=Array.from(this.colors.values());this.colors.forEach((a,l)=>!s.includes(l)&&this.colors.delete(l));const{palette:i}=this.internal;t.forEach(a=>{if(this.colors.has(a.key))return;const l=i.find(u=>!o.includes(u))??i[0];this.colors.set(a.key,l),o.push(l)})}}const ki=h.z.enum(["acquired","released","overridden","failed"]),_i=h.z.object({name:h.z.string(),authority:h.z.number().default(0),status:ki.optional(),needsControlOf:x.channel.keyZ.array().default([])}),ts={acquire:h.z.function({input:h.z.tuple([]),output:h.z.void()}),release:h.z.function({input:h.z.tuple([]),output:h.z.void()})};class ns extends w.Composite{static TYPE="Controller";static METHODS=ts;schema=_i;methods=ts;registry=new Map;writer;afterUpdate(e){const{internal:t}=this;t.instrumentation=I.useInstrumentation(e),t.addStatus=w.useAdder(e),t.runAsync=w.useErrorHandler(e);const s=He(e),o=ct.use(e);t.stateProv=o,t.telemCtx=Yo(e,this,t.telemCtx),t.client=s}afterDelete(){const{internal:e}=this;e.runAsync(()=>this.doRelease(),"failed to release control")}async updateNeedsControlOf(){const{client:e}=this.internal;if(e==null)return;const t=new Set([]);for(const o of this.registry.keys())(await o.needsControlOf(e)).forEach(a=>a!==0&&t.add(a));const s=Array.from(t);r.compare.unorderedPrimitiveArrays(this.state.needsControlOf,s)!==r.compare.EQUAL&&this.setState(o=>({...o,needsControlOf:s}))}acquire(){this.internal.runAsync(()=>this.doAcquire(),"failed to acquire control")}release(){this.internal.runAsync(()=>this.doRelease(),"failed to release control")}async doAcquire(){const{client:e,addStatus:t}=this.internal;if(e==null)return t({message:`Cannot acquire control on ${this.state.name} because no Core has been connected.`,variant:"warning"});try{await this.updateNeedsControlOf();const s=this.state.needsControlOf;if(s.length===0)return t({message:`Cannot acquire control on ${this.state.name} because there are no channels to control.`,variant:"warning"});const o=x.TimeStamp.now().sub(r.TimeSpan.milliseconds(1));this.writer=await e.openWriter({start:o,channels:s,controlSubject:{key:this.key,name:this.state.name},authorities:this.state.authority}),this.setState(i=>({...i,status:"acquired"}))}catch(s){if(this.setState(o=>({...o,status:"failed"})),!(s instanceof Error))throw s;t({variant:"error",message:`${this.state.name} failed to acquire control`,description:s.message})}}async doRelease(){try{await this.writer?.close()}catch(e){this.internal.addStatus({message:`${this.state.name} failed to release control: ${e.message}`,variant:"error"})}finally{this.setState(e=>({...e,status:"released"})),this.writer=void 0}}async set(e){this.writer==null&&await this.doAcquire(),await this.writer?.write(e)}async setAuthority(e,t){this.writer==null&&await this.doAcquire(),await this.writer?.setAuthority(Object.fromEntries(e.map(s=>[s,t])))}async releaseAuthority(e){this.writer==null&&await this.doAcquire(),await this.writer?.setAuthority(Object.fromEntries(e.map(t=>[t,this.state.authority])))}deleteTelem(e){this.registry.delete(e),this.updateNeedsControlOf()}create(e){const{internal:t}=this,o=(()=>{switch(e.type){case tn.TYPE:{const i=new tn(this,t.runAsync,e.props);return this.registry.set(i,null),i}case sn.TYPE:{const i=new sn(this,this.internal.stateProv,e.props);return this.registry.set(i,null),i}case nn.TYPE:return new nn(this,t.runAsync,e.props);default:return null}})();return o!=null&&this.updateNeedsControlOf(),o}}const Oi=h.z.object({channel:h.z.number()});class tn extends pn{static TYPE="controlled-numeric-telem-sink";controller;runAsync;schema=Oi;constructor(e,t,s){super(s),this.controller=e,this.runAsync=t}invalidate(){}cleanup(){this.controller.deleteTelem(this)}async needsControlOf(e){if(this.props.channel===0)return[];const t=await e.channels.retrieve(this.props.channel),s=[t.key];return t.index!==0&&s.push(t.index),s}set(...e){this.runAsync(async()=>{const{client:t}=this.controller.internal;if(t==null)throw new x.DisconnectedError("No Core connected");if(this.props.channel===0)throw new x.ValidationError("No command channel specified for actuator");const s=await t.channels.retrieve(this.props.channel),o={[s.key]:e};if(s.index!==0){const i=await t.channels.retrieve(s.index),a=x.TimeStamp.now();o[i.key]=Array.from({length:e.length},(l,u)=>a.add(r.TimeSpan.nanoseconds(u)))}await this.controller.set(o)},"Failed to command channel")}}const Xh=n=>({type:tn.TYPE,props:n,variant:"sink",valueType:"number"}),Mi=h.z.object({authority:h.z.number().default(x.control.ABSOLUTE_AUTHORITY),channel:h.z.number()});class nn extends pn{static TYPE="acquire-channel-control";controller;runAsync;schema=Mi;constructor(e,t,s){super(s),this.controller=e,this.runAsync=t}cleanup(){this.controller.deleteTelem(this)}async needsControlOf(e){const t=await e.channels.retrieve(this.props.channel),s=[t.key];return t.index!==0&&s.push(t.index),s}set(e){this.runAsync(async()=>{const{controller:t}=this,{client:s}=t.internal;if(s==null)return;const o=await s.channels.retrieve(this.props.channel),i=[o.key];o.index!==0&&i.push(o.index),e?await this.controller.setAuthority(i,this.props.authority):await this.controller.releaseAuthority(i)},"failed to set channel authority")}}const Gh=n=>({type:nn.TYPE,props:n,variant:"sink",valueType:"boolean"}),Di=h.z.object({channel:h.z.number()}),Kh=h.z.object({valid:h.z.boolean(),color:r.color.colorZ.optional(),authority:h.z.number()});class sn extends W{static TYPE="controlled-status-source";prov;valid=!1;stopListening;controller;schema=Di;constructor(e,t,s){super(s),this.prov=t,this.controller=e}async needsControlOf(){return[]}maybeRevalidate(){if(this.valid)return;const{channel:e}=this.props;this.stopListening?.();const t=r.control.filterTransfersByChannelKey(e);this.stopListening=this.prov.onChange(s=>{s.length>0&&t(s).length===0||this.notify?.()}),this.valid=!0}value(){this.maybeRevalidate();const e=x.TimeStamp.now();if(this.props.channel===0)return{name:this.controller.key,key:this.controller.key,variant:"disabled",message:"No Channel",time:e,details:{valid:!1,authority:0}};const t=this.prov.get(this.props.channel);return t==null?{name:this.controller.key,key:this.controller.key,variant:"disabled",message:"Uncontrolled",time:e,details:{valid:!0,color:void 0,authority:0}}:{name:this.controller.key,key:t.subject.key,variant:t.subject.key===this.controller.key?"success":"error",message:`Controlled by ${t.subject.name}`,time:e,details:{valid:!0,color:t.subjectColor,authority:t.authority}}}cleanup(){this.controller.deleteTelem(this),this.stopListening?.()}}const Qh=n=>({type:sn.TYPE,props:n,variant:"source",valueType:"status"}),Ai=h.z.object({color:r.color.colorZ.optional()}).default({color:void 0}),Ii=h.z.object({statusSource:Ls.default(Cs),colorSource:hn.default(dt),status:r.status.statusZ(Ai),color:r.color.colorZ.optional()});class ss extends w.Leaf{static TYPE="Indicator";schema=Ii;stopListeningStatus;stopListeningColor;afterUpdate(e){const{internal:t}=this,{statusSource:s,colorSource:o}=this.state;t.statusSource=U(e,s,t.statusSource),t.colorSource=U(e,o,t.colorSource),this.updateState(),this.stopListeningStatus?.(),this.stopListeningColor?.(),this.stopListeningStatus=t.statusSource.onChange(this.updateState.bind(this)),this.stopListeningColor=t.colorSource.onChange(this.updateState.bind(this))}afterDelete(){this.internal.statusSource.cleanup?.(),this.internal.colorSource.cleanup?.()}render(){}updateState(){const e=this.internal.colorSource.value(),t=this.internal.statusSource.value();r.color.equals(e,this.state.color)&&t.message===this.state.status.message&&r.color.equals(t.details?.color,this.state.status.details?.color)||this.setState(s=>({...s,color:e,status:t}))}}const zi=h.z.object({needsControlOf:x.channel.keyZ.array(),states:Li.array(),colors:h.z.record(h.z.string(),h.z.string()).default({})});class rs extends w.Leaf{static TYPE="Legend";schema=zi;afterUpdate(e){const{internal:t}=this;t.stateProv=ct.use(e),t.stateProv.setColorOverrides(this.state.colors);const s=this.state.needsControlOf;t.disconnectStateProv?.();const o=r.control.filterTransfersByChannelKey(...s),i=t.stateProv.get(s);this.setState(a=>({...a,states:i})),t.disconnectStateProv=t.stateProv.onChange(a=>{if(a.length>0&&o(a).length===0)return;const l=t.stateProv.get(s);this.setState(u=>({...u,states:l}))})}afterDelete(){const{internal:e}=this;e.disconnectStateProv?.()}render(){}}const Jh={[ns.TYPE]:ns,[ct.TYPE]:ct,[ss.TYPE]:ss,[es.TYPE]:es,[rs.TYPE]:rs},Yi=["fire","momentary","pulse"],ed=h.z.enum(Yi),Ni=h.z.object({sink:un.default(cn),mode:ed.default("fire")}),os={onMouseDown:h.z.function({input:h.z.tuple([]),output:h.z.void()}),onMouseUp:h.z.function({input:h.z.tuple([]),output:h.z.void()})};class is extends w.Leaf{static TYPE="Button";static METHODS=os;schema=Ni;methods=os;afterUpdate(e){const{sink:t}=this.state;this.internal.sink=qe(e,t,this.internal.sink)}onMouseDown(){const{mode:e}=this.state;e==="momentary"?this.internal.sink.set(!0):e==="pulse"&&this.internal.sink.set(!0,!1)}onMouseUp(){const{mode:e}=this.state;e==="fire"?this.internal.sink.set(!0):e==="momentary"&&this.internal.sink.set(!1)}afterDelete(){this.internal.sink.cleanup?.()}}const td={[is.TYPE]:is},nd=h.z.object({region:r.box.box,clearOverScan:r.xy.crudeZ.default(0),visible:h.z.boolean().default(!0),autoRenderInterval:h.z.number().default(1e3)}),Zr=["upper2d","lower2d"];class Fe extends w.Composite{static TYPE="Table";static stateZ=nd;schema=Fe.stateZ;afterUpdate(e){const{internal:t}=this;t.renderCtx=I.Context.use(e),t.handleError=w.useErrorHandler(e),t.autoRenderInterval??=setInterval(()=>this.state.visible&&this.requestRender("low"),this.state.autoRenderInterval),on(e,()=>{this.state.visible&&this.requestRender("low")}),!(!this.state.visible&&!this.prevState.visible)&&this.requestRender("high")}afterDelete(){this.internal.autoRenderInterval!=null&&clearInterval(this.internal.autoRenderInterval),this.requestRender("high")}render(){if(this.deleted)return;const e=r.box.copy(this.state.region);if(!this.state.visible)return()=>this.internal.renderCtx.erase(e,this.state.clearOverScan);const{renderCtx:t,handleError:s}=this.internal,o=r.scale.XY.translate(r.box.topLeft(this.state.region)),i=t.scissor(this.state.region,r.xy.construct(this.state.clearOverScan),Zr);try{for(const a of this.children)a.render({viewportScale:o})}catch(a){s(a,"Failed to render table")}finally{i()}return()=>this.internal.renderCtx.erase(e,this.state.clearOverScan)}requestRender(e){const{renderCtx:t}=this.internal;t.loop.set({key:`${Fe.TYPE}-${this.key}`,render:this.render.bind(this),priority:e,canvases:Zr})}}const sd={[Fe.TYPE]:Fe};h.z.enum(["small","medium","large","huge"]);const rd=h.z.object({box:r.box.box,telem:dn.default(Es),backgroundTelem:hn.default(dt),level:ge.levelZ.default("p"),color:r.color.colorZ.default(r.color.ZERO),precision:h.z.number().default(2),minWidth:h.z.number().default(60),width:h.z.number().optional(),notation:r.notation.notationZ.default("standard"),location:r.location.xy.default({x:"left",y:"center"}),units:h.z.string().default("RPM"),bounds:r.bounds.bounds.default(r.bounds.construct(0,100)),barWidth:h.z.number().default(12)}),od=["upper2d","lower2d"];class ut extends w.Leaf{static TYPE="gauge";static z=rd;schema=ut.z;afterUpdate(e){const{internal:t}=this;t.render=I.Context.use(e),t.theme=w.use(e),r.color.isZero(this.state.color)?t.textColor=t.theme.colors.gray.l8:t.textColor=this.state.color,t.telem=U(e,this.state.telem,t.telem),t.stopListening?.(),t.stopListening=t.telem.onChange(()=>this.requestRender()),t.backgroundTelem=U(e,this.state.backgroundTelem,t.backgroundTelem),t.stopListeningBackground?.(),t.stopListeningBackground=t.backgroundTelem.onChange(()=>this.requestRender()),t.requestRender=bs(e),t.strokeColor=r.color.isZero(this.state.color)?t.theme.colors.visualization.palettes.default[0]:this.state.color;const s=this.state.box,o=r.box.width(s)/2,{barWidth:i}=this.state;t.outerRadius=o-8,t.innerRadius=t.outerRadius-i;const a=Math.PI/2;t.gaugeStartAngle=3*Math.PI/4,t.gaugeAngleRange=2*Math.PI-a,t.gaugeEndAngle=t.gaugeStartAngle+t.gaugeAngleRange,t.labelRadius=t.outerRadius+12,t.labelInwardShift=12,t.centerPos=r.box.center(s);const l=t.centerPos.y+t.labelRadius*Math.sin(t.gaugeStartAngle)+6;t.minLabelPos=r.xy.construct(t.centerPos.x+t.labelRadius*Math.cos(t.gaugeStartAngle)+t.labelInwardShift,l),t.maxLabelPos=r.xy.construct(t.centerPos.x+t.labelRadius*Math.cos(t.gaugeEndAngle)-t.labelInwardShift,l),t.valueTextPos=r.xy.translateY(t.centerPos,-6),t.unitsTextPos=r.xy.translateY(t.centerPos,r.box.height(s)/9),t.textLevel=this.state.level,t.labelLevel=ge.downLevel(ge.downLevel(t.textLevel)),this.requestRender()}afterDelete(){const{internal:e}=this;e.stopListening?.(),e.stopListeningBackground?.(),e.telem.cleanup?.(),e.backgroundTelem.cleanup?.(),e.requestRender==null?e.render.erase(r.box.construct(this.state.box),r.xy.ZERO,...od):e.requestRender("layout")}requestRender(){const{requestRender:e}=this.internal;e!=null?e("layout"):this.render({})}render({viewportScale:e=r.scale.XY.IDENTITY}){const{internal:t}=this,s=t.render.upper2d.applyScale(e),o=new Ee(s,t.theme),i=t.telem.value(),{lower:a,upper:l}=this.state.bounds,u=Number(i),c=r.bounds.clamp(this.state.bounds,u),d=l-a,f=d===0?0:(c-a)/d,p=t.gaugeStartAngle+f*t.gaugeAngleRange;o.text({text:i,position:t.valueTextPos,shade:10,level:t.textLevel,align:"middle",justify:"center",weight:450,code:!0,useAtlas:!0}),o.text({text:this.state.units,position:t.unitsTextPos,shade:8,level:ge.downLevel(t.textLevel),align:"middle",justify:"center",code:!0,useAtlas:!0}),o.text({text:a.toString(),position:t.minLabelPos,shade:7,level:t.labelLevel,align:"middle",justify:"center",code:!0,useAtlas:!0}),o.text({text:l.toString(),position:t.maxLabelPos,shade:7,level:t.labelLevel,align:"middle",justify:"center",code:!0,useAtlas:!0}),o.circle({stroke:t.theme.colors.gray.l5,radius:{inner:t.innerRadius,outer:t.outerRadius},position:t.centerPos,angle:{lower:t.gaugeStartAngle,upper:t.gaugeEndAngle},lineCap:"round"}),o.circle({stroke:t.strokeColor,radius:{inner:t.innerRadius,outer:t.outerRadius},position:t.centerPos,angle:{lower:t.gaugeStartAngle,upper:p},lineCap:"round"})}}const id={[ut.TYPE]:ut},Zi=h.z.object({sink:oo.default(Jr)}),as={set:h.z.function({input:h.z.tuple([h.z.string()]),output:h.z.void()})};class ls extends w.Leaf{static TYPE="Input";static METHODS=as;schema=Zi;methods=as;afterUpdate(e){const{sink:t}=this.state;this.internal.sink=qe(e,t,this.internal.sink)}set(e){this.internal.sink.set(e)}afterDelete(){this.internal.sink.cleanup?.()}}const ad={[ls.TYPE]:ls},Ui=h.z.object({enabled:h.z.boolean(),source:Rs.default(vs)});class cs extends w.Leaf{static TYPE="Light";schema=Ui;afterUpdate(e){const{internal:t}=this;this.internal.source=U(e,this.state.source,t.source),this.updateEnabledState(),t.stopListening?.(),t.stopListening=t.source.onChange(()=>this.updateEnabledState())}updateEnabledState(){const e=this.internal.source.value();e!==this.state.enabled&&this.setState(t=>({...t,enabled:e}))}afterDelete(){this.internal.stopListening?.(),this.internal.source.cleanup?.()}}const ld={[cs.TYPE]:cs},Bi=h.z.object({value:h.z.number(),sink:ro.default(Qr),source:Ps.default(ws)}),us={set:h.z.function({input:h.z.tuple([h.z.number()]),output:h.z.void()})};class hs extends w.Leaf{static TYPE="Setpoint";static METHODS=us;schema=Bi;methods=us;afterUpdate(e){const{sink:t,source:s}=this.state,{internal:o}=this;o.source=U(e,s,o.source),o.sink=qe(e,t,o.sink),this.updateValue(),o.stopListening?.(),o.stopListening=o.source.onChange(()=>this.updateValue())}set(e){this.internal.sink.set(e)}updateValue(){const e=this.internal.source.value();e===this.state.value||isNaN(e)||this.setState(t=>({...t,value:e}))}afterDelete(){const{internal:e}=this;e.stopListening?.(),e.source.cleanup?.(),e.sink.cleanup?.()}}const cd={[hs.TYPE]:hs},ud=h.z.object({key:h.z.string(),value:h.z.number()}),Fi=h.z.object({key:h.z.string().nullable().default(null),options:h.z.array(ud).default([]),source:Ps.default(ws)});class ds extends w.Leaf{static TYPE="StateIndicator";schema=Fi;afterUpdate(e){const{internal:t}=this;this.internal.source=U(e,this.state.source,t.source),this.updateMatchedOption(),t.stopListening?.(),t.stopListening=t.source.onChange(()=>this.updateMatchedOption())}updateMatchedOption(){const e=this.internal.source.value();if(isNaN(e))return;const s=this.state.options.find(o=>o.value===e)?.key??null;s!==this.state.key&&this.setState(o=>({...o,key:s}))}afterDelete(){this.internal.stopListening?.(),this.internal.source.cleanup?.()}}const hd={[ds.TYPE]:ds},$i=h.z.object({enabled:h.z.boolean(),sink:un.default(cn),source:Rs.default(vs)}),fs={toggle:h.z.function({input:h.z.tuple([]),output:h.z.void()})};class ps extends w.Leaf{static TYPE="Toggle";static METHODS=fs;schema=$i;methods=fs;afterUpdate(e){this.internal.addStatus=w.useOptionalAdder(e);const{sink:t,source:s}=this.state,{internal:o}=this;o.source=U(e,s,o.source),o.sink=qe(e,t,o.sink),this.updateEnabledState(),o.stopListening?.(),o.stopListening=o.source.onChange(()=>this.updateEnabledState())}toggle(){const{enabled:e}=this.state;this.internal.sink.set(!e)}updateEnabledState(){const e=this.internal.source.value();e!==this.state.enabled&&this.setState(t=>({...t,enabled:e}))}afterDelete(){this.internal.stopListening?.(),this.internal.source.cleanup?.(),this.internal.sink.cleanup?.()}}const dd={[ps.TYPE]:ps},Mn={useAtlas:!0},fd=h.z.object({box:r.box.box,telem:dn.default(Es),backgroundTelem:hn.default(dt),level:ge.levelZ.default("p"),color:r.color.colorZ.default(r.color.ZERO),precision:h.z.number().default(2),stalenessTimeout:h.z.number().default(5),stalenessColor:r.color.colorZ.default(r.color.ZERO),minWidth:h.z.number().default(60),width:h.z.number().optional(),notation:r.notation.notationZ.default("standard"),location:r.location.xy.default({x:"left",y:"center"}),useWidthForBackground:h.z.boolean().default(!1),valueBackgroundShift:r.xy.xy.default(r.xy.ZERO),valueBackgroundOverScan:r.xy.xy.default(r.xy.ZERO)}),pd=["upper2d","lower2d"];class $e extends w.Leaf{static TYPE="value";static z=fd;schema=$e.z;afterUpdate(e){const{internal:t}=this;t.renderCtx=I.Context.use(e),t.theme=w.use(e),t.telem=U(e,this.state.telem,t.telem),t.stopListening?.(),t.stopListening=t.telem.onChange(()=>{t.lastReceived=performance.now(),this.requestRender()}),t.fontString=Je.fontString(t.theme,{level:this.state.level,code:!0}),t.backgroundTelem=U(e,this.state.backgroundTelem,t.backgroundTelem),t.stopListeningBackground?.(),t.stopListeningBackground=t.backgroundTelem.onChange(()=>this.requestRender()),t.requestRender=bs(e),this.requestRender()}afterDelete(){const{internal:e}=this;e.stopListening?.(),e.stopListeningBackground?.(),e.telem.cleanup?.(),e.backgroundTelem.cleanup?.(),e.requestRender==null?e.renderCtx.erase(r.box.construct(this.state.box),r.xy.ZERO,...pd):e.requestRender("layout")}requestRender(){const{requestRender:e}=this.internal;e!=null?e("layout"):this.render({})}get fontHeight(){const{theme:e}=this.internal;return e.typography[this.state.level].size*e.sizes.base}maybeUpdateWidth(e){const{theme:t}=this.internal,s=e+t.sizes.base+this.fontHeight;this.state.width==null||this.state.width+this.fontHeight*.5<s||this.state.minWidth>s&&this.state.width!==this.state.minWidth?this.setState(o=>({...o,width:Math.max(s,o.minWidth)})):this.state.width-this.fontHeight>s&&this.setState(o=>({...o,width:Math.max(s,o.minWidth)}))}getTextColor(){const{theme:e}=this.internal;return performance.now()-this.internal.lastReceived>this.state.stalenessTimeout*1e3?r.color.isZero(this.state.stalenessColor)?e.colors.warning.m1:this.state.stalenessColor:r.color.isZero(this.state.color)?r.color.pickByContrast(e.colors.border,e.colors.gray.l11,e.colors.gray.l0):r.color.pickByContrast(e.colors.border,e.colors.gray.l11,this.state.color)}render({viewportScale:e=r.scale.XY.IDENTITY}){const{renderCtx:t,telem:s,backgroundTelem:o,fontString:i,requestRender:a}=this.internal,{location:l,box:u}=this.state;if(r.box.areaIsZero(u))return;const c=r.box.topLeft(u),d=r.box.width(u),f=r.box.height(u),p=t.lower2d.applyScale(e);let g=s.value();p.font=i;const T=this.fontHeight,y=g[0]=="-";y&&(g=g.slice(1));const{theme:v}=this.internal,R=p.textDimensions(g,Mn),L=R.width+v.sizes.base,k=R.height;a==null&&t.erase(r.box.construct(this.prevState.box)),this.maybeUpdateWidth(L);const C={...r.xy.ZERO};l.x==="left"?C.x=6+T*.75:l.x==="center"&&(C.x=d/2-L/2),l.y==="center"&&(C.y=f/2+k/2);const Z=r.xy.translate(c,C);if(this.state.backgroundTelem.type!=dt.type){const M=o.value();if(!r.color.isZero(M)){p.fillStyle=r.color.hex(M);const V=this.state.useWidthForBackground?this.state.width??this.state.minWidth:r.box.width(u);p.fillRect(...r.xy.couple(r.xy.translate(c,this.state.valueBackgroundShift)),V+this.state.valueBackgroundOverScan.x,f+this.state.valueBackgroundOverScan.y)}}const b=this.getTextColor();p.fillStyle=r.color.hex(b),y&&p.fillText("-",...r.xy.couple(r.xy.translateX(Z,-T*.6)),void 0,Mn),p.fillText(g,...r.xy.couple(Z),void 0,Mn)}}const Hi={[$e.TYPE]:$e},md=Object.freeze(Object.defineProperty({__proto__:null,REGISTRY:Hi,Value:$e},Symbol.toStringTag,{value:"Module"}));exports.AcquireChannelControl=nn;exports.AuthoritySource=sn;exports.Base=we;exports.Bottom=ci;exports.Button=is;exports.Canvas=Ht;exports.Chip=es;exports.Client=Fr;exports.Controller=ns;exports.Diagram=Fl;exports.Diagram$1=xe;exports.FLUX_STORE_CONFIG=Hh;exports.FLUX_STORE_CONFIG$1=ha;exports.FLUX_STORE_CONFIG$2=Vh;exports.FLUX_STORE_KEY=Bh;exports.FLUX_STORE_KEY$1=la;exports.FLUX_STORE_KEY$2=qh;exports.Gauge=ut;exports.Indicator=ss;exports.Input=ls;exports.Legend=rs;exports.Light=cs;exports.Line=$t;exports.LinePlot=Jn;exports.Log=lt;exports.MODES=Yi;exports.Measure=at;exports.PROVIDER_TYPE=ys;exports.PROVIDER_TYPE$1=gn;exports.Provider=kt;exports.Provider$1=Jt;exports.REGISTRY=Yh;exports.REGISTRY$1=id;exports.REGISTRY$10=cd;exports.REGISTRY$11=yi;exports.REGISTRY$12=oh;exports.REGISTRY$13=Ti;exports.REGISTRY$14=Yl;exports.REGISTRY$15=ld;exports.REGISTRY$16=ad;exports.REGISTRY$17=Vo;exports.REGISTRY$18=Jh;exports.REGISTRY$19=Wo;exports.REGISTRY$2=sd;exports.REGISTRY$20=td;exports.REGISTRY$3=Uh;exports.REGISTRY$4=Hi;exports.REGISTRY$5=bi;exports.REGISTRY$6=dd;exports.REGISTRY$7=qo;exports.REGISTRY$8=Hr;exports.REGISTRY$9=hd;exports.RELATIONSHIPS_FLUX_STORE_KEY=ea;exports.RELATIONSHIP_FLUX_STORE_CONFIG=ra;exports.RESOURCES_FLUX_STORE_KEY=ta;exports.RESOURCE_FLUX_STORE_CONFIG=aa;exports.Right=hi;exports.Rule=ot;exports.ScopedUnaryStore=Ur;exports.SetChannelValue=tn;exports.Setpoint=hs;exports.StateIndicator=ds;exports.StateProvider=ct;exports.Table=Fe;exports.Toggle=ps;exports.Tooltip=it;exports.Top=ui;exports.Value=$e;exports.XAxis=en;exports.YAxis=Qt;exports.ZERO_CONTEXT_VALUE=ms;exports.acquireChannelControl=Gh;exports.acquireChannelControlPropsZ=Mi;exports.aether=eh;exports.authoritySource=Qh;exports.authoritySourceDetailsZ=Kh;exports.authoritySourceProps=Di;exports.axisStateZ=Qs;exports.baseAxisStateZ=xt;exports.buttonMethodsZ=os;exports.buttonStateZ=Ni;exports.cachedRetrieveForSubject=Wr;exports.canvas=Bl;exports.canvasStateZ=Bs;exports.channelData=fo;exports.chipStateZ=Ri;exports.chipStatusDetailsZ=Ci;exports.color=Oe;exports.colorGradient=ko;exports.control=on;exports.controllerMethodsZ=ts;exports.controllerStateZ=_i;exports.createRegistry=Ji;exports.createStore=Br;exports.diagramStateZ=Fs;exports.external=Cl;exports.indicatorStateZ=Ii;exports.indicatorStatusDetailsZ=Ai;exports.interpolate=ln;exports.interpolateNumber=nt;exports.interpolateRgb=zn;exports.interpolateString=Kr;exports.legendStateZ=zi;exports.linePlotMethodsZ=wi;exports.linePlotStateZ=vi;exports.logState=Ei;exports.measure=Mh;exports.measureStateZ=tr;exports.methodsZ=as;exports.methodsZ$1=us;exports.newCanvas=li;exports.newTickFactory=Kn;exports.parseAutoBounds=gi;exports.partialUpdate=ji;exports.provider=Gi;exports.providerStateZ=qr;exports.providerStateZ$1=xi;exports.providerStateZ$2=Us;exports.regions=me;exports.request=ie;exports.retrieveForSubject=da;exports.rollingAverage=Po;exports.rollingAverageProps=Ys;exports.ruleStateZ=Js;exports.scaleNumber=Oo;exports.scopeStore=Dn;exports.setChannelValue=Xh;exports.setChannelValuePropsZ=Oi;exports.setpoint=vo;exports.sinkPipeline=co;exports.sinkPipelinePropsZ=Ms;exports.sourcePipeline=lo;exports.sourcePipelinePropsZ=_s;exports.stateProviderStateZ=Pi;exports.stateZ=jo;exports.stateZ$1=Zi;exports.stateZ$2=Ui;exports.stateZ$3=Bi;exports.stateZ$4=Fi;exports.statusZ=ki;exports.streamChannelData=po;exports.streamChannelValue=mo;exports.streamChannelValuePropsZ=Ds;exports.stringSourceSpecZ=dn;exports.stringifyNumber=Ro;exports.stringifyNumberProps=zs;exports.sugaredStateZ=Li;exports.tickFactoryProps=Ks;exports.tickType=Gs;exports.toggleMethodsZ=fs;exports.toggleStateZ=$i;exports.tooltip=hh;exports.tooltipStateZ=er;exports.useOptionalRequestor=bs;exports.useRequestor=an;exports.value=md;exports.withinBounds=wo;exports.withinBoundsProps=Is;exports.withinSizeThreshold=fi;exports.xAxisStateZ=ih;exports.yAxisStateZ=th;
53
+ `,jo=h.z.object({x:Mt,y:Mt,label:h.z.string().optional(),color:r.color.colorZ,strokeWidth:h.z.number().default(1),downsample:h.z.number().min(1).max(50).default(1),downsampleMode:Ns.default("decimate"),visible:h.z.boolean().default(!0)}),Ll=(n,e,t)=>n===-1||e===-1||n>=t.series.length?NaN:Number(t.series[n].at(e)),kl=r.TimeSpan.milliseconds(2);r.xy.NAN,r.xy.NAN,r.color.ZERO,r.bounds.ZERO;const _l=(n,e)=>e.equals(r.DataType.UINT8)?n.UNSIGNED_BYTE:n.FLOAT;class mr extends I.GLProgram{translationBufferCache=new Map;constructor(e,t,s){super(e,t,s),this.translationBufferCache=new Map}bindState({strokeWidth:e,color:t}){return this.uniformColor("u_color",t),this.attrStrokeWidth(e)}bindScale(e,t){const s=r.xy.scale(e.scale,t.scale),o=r.xy.translate(r.xy.scale(t.scale,e.offset),t.offset);this.uniformXY("u_scale_aggregate",s),this.uniformXY("u_offset_aggregate",o)}draw({x:e,y:t,count:s,downsample:o,xOffset:i,yOffset:a},l,u,c){const{gl:d}=this.renderCtx;this.bindAttrBuffer("x",e.glBuffer,o,i,u),this.bindAttrBuffer("y",t.glBuffer,o,a,c),d.drawArraysInstanced(d.LINE_STRIP,0,s/o,l)}bindAttrBuffer(e,t,s,o=0,i){const{gl:a}=this.renderCtx;a.bindBuffer(a.ARRAY_BUFFER,t);const l=a.getAttribLocation(this.prog,`a_${e}`),u=_l(a,i),c=i.density.valueOf();i.equals(r.DataType.UINT8)?a.vertexAttribIPointer(l,1,u,c*s,c*o):a.vertexAttribPointer(l,1,u,!1,c*s,c*o),a.enableVertexAttribArray(l)}getAndBindTranslationBuffer(e){const{gl:t}=this.renderCtx,s=`${this.renderCtx.aspect}:${e}`,o=this.translationBufferCache.get(s);if(o!=null)return t.bindBuffer(t.ARRAY_BUFFER,o.glBuffer),o;const i=t.createBuffer();if(i==null)throw new x.UnexpectedError("Failed to create buffer from WebGL context");const a=Ml(this.renderCtx.aspect,e);t.bindBuffer(t.ARRAY_BUFFER,i),t.bufferData(t.ARRAY_BUFFER,a,t.DYNAMIC_DRAW);const l={glBuffer:i,jsBuffer:a};return this.translationBufferCache.set(s,l),l}attrStrokeWidth(e){const{gl:t}=this.renderCtx,{jsBuffer:s}=this.getAndBindTranslationBuffer(e),o=t.getAttribLocation(this.prog,"a_translate");return t.vertexAttribPointer(o,2,t.FLOAT,!1,0,0),t.enableVertexAttribArray(o),t.vertexAttribDivisor(o,1),s.length/2}}class _e{static CONTEXT_KEY="pluto-line-gl-program";uint8HybridProgram;float32Program;constructor(e){this.uint8HybridProgram=new mr(e,Pl,pr),this.float32Program=new mr(e,Rl,pr)}get gl(){return this.uint8HybridProgram.renderCtx.gl}getProgram(e){return e.equals(r.DataType.UINT8)?this.uint8HybridProgram:this.float32Program}static create(e,t){const s=new _e(t);return e.set(_e.CONTEXT_KEY,s),s}static use(e){const t=e.get(_e.CONTEXT_KEY);if(t==null)throw new x.UnexpectedError("GLProgram not found");return t}}class $t extends w.Leaf{static TYPE="line";schema=jo;afterUpdate(e){const{internal:t}=this,s={onStatusChange:w.useAdder(e)};t.xTelem=U(e,this.state.x,t.xTelem,s),t.yTelem=U(e,this.state.y,t.yTelem,s),t.instrumentation=I.useInstrumentation(e,"line"),t.lineCtx=_e.use(e),t.requestRender=an(e),t.stopListeningXTelem?.(),t.stopListeningYTelem?.(),t.stopListeningXTelem=t.xTelem.onChange(()=>t.requestRender("data")),t.stopListeningYTelem=t.yTelem.onChange(()=>t.requestRender("data")),t.requestRender("layout"),(t.xDownsampler?.props.mode!==this.state.downsampleMode||t.xDownsampler?.props.windowSize!==this.state.downsample)&&(t.xDownsampler=new st({mode:this.state.downsampleMode,windowSize:this.state.downsample}),t.yDownsampler=new st({mode:this.state.downsampleMode,windowSize:this.state.downsample}))}afterDelete(){const{internal:e}=this;e.xTelem.cleanup?.(),e.yTelem.cleanup?.(),e.requestRender("layout")}xBounds(){return this.internal.xTelem.value()[0]}yBounds(){return this.internal.yTelem.value()[0]}findByXValue(e,t){const{xTelem:s,yTelem:o}=this.internal;let[,i]=s.value();i=this.internal.xDownsampler.transform(i);let[a,l]=[-1,-1];i.series.find((v,R)=>{const L=v.binarySearch(t),k=L>=0&&L<v.length;return k&&([a,l]=[L,R]),k});const{key:u}=this,{color:c,label:d}=this.state,f={key:u,color:c,label:d,position:{x:0,y:0},value:{x:NaN,y:NaN},bounds:{lower:0,upper:0}};if(a===-1||l===-1||!this.state.visible)return f;const p=i.series[l];f.value.x=Ll(l,a,i);let[,g]=o.value();g=this.internal.yDownsampler.transform(g);const T=g.series.find(v=>r.bounds.contains(v.alignmentBounds,p.alignment+BigInt(a)));if(T==null)return f;const y=Number(T.alignment-p.alignment);return f.value.y=Number(T.at(a-y)),f.bounds={...T.bounds},f.position={x:e.dataToDecimalScale.x.pos(f.value.x),y:e.dataToDecimalScale.y.pos(f.value.y)},f}render(e){if(this.deleted||!this.state.visible)return;const{downsample:t}=this.state,{xTelem:s,yTelem:o,lineCtx:i,xDownsampler:a,yDownsampler:l}=this.internal,{dataToDecimalScale:u,exposure:c}=e;let[[,d],[,f]]=[s.value(),o.value()];if(d=a.transform(d),f=l.transform(f),d.updateGLBuffer(i.gl),f.updateGLBuffer(i.gl),d.length===0||f.length===0)return;const p=i.getProgram(f.dataType),g=Nl(d,f,c,t,this.state.downsampleMode,kl);this.internal.instrumentation.L.debug("render",()=>({key:this.key,downsample:t,scale:u.transform,props:e.region,ops:Zl(g)}));const T=p.setAsActive(),y=p.bindState(this.state),v=p.renderCtx.scaleRegion(e.region).transform;g.forEach(R=>{const L=zl(u,R).transform;p.bindScale(L,v),p.draw(R,y,d.dataType,f.dataType)}),T()}}const Ol=5e3,Ml=(n,e)=>Il(Al(n),e).map((t,s)=>Math.floor(s/Dl)*(1/(Ol*n))*t),Dl=5,Al=n=>new Float32Array([0,0,0,n,0,-n,1,0,-1,0]),Il=(n,e)=>{const t=new Float32Array(n.length*e);for(let s=0;s<e;s++)t.set(n,s*n.length);return t},zl=(n,e)=>n.translate(n.x.dim(Number(e.x.sampleOffset)),n.y.dim(Number(e.y.sampleOffset))),Yl={[$t.TYPE]:$t},Nl=(n,e,t,s,o,i)=>{if(n.series.length===0||e.series.length===0)return[];const a=[];return n.series.forEach(l=>e.series.forEach(u=>{if(!Ul(l,u,i))return;let c=0n,d=0n;l.alignment<u.alignment?c=u.alignment-l.alignment:u.alignment<l.alignment&&(d=l.alignment-u.alignment);const f=r.math.min(r.bounds.span(l.alignmentBounds)-c,r.bounds.span(u.alignmentBounds)-d);if(f===0n)return;let p=r.clamp(Math.round(t*4*Number(f)),s,51);o!=="decimate"&&(p=1);const g=Number(f/l.alignmentMultiple),T=Number(c/l.alignmentMultiple),y=Number(d/u.alignmentMultiple);a.push({x:l,y:u,xOffset:T,yOffset:y,count:g,downsample:p})})),a},Zl=n=>n.map(e=>({...e,x:e.x.digest,y:e.y.digest})),Ul=(n,e,t)=>{if(n.alignmentMultiple!==e.alignmentMultiple)return console.warn("encountered two series with different alignment multiples in draw operations",{x:n.digest,y:e.digest}),!1;const s=n.timeRange.overlapsWith(e.timeRange,t),o=r.bounds.overlapsWith(n.alignmentBounds,e.alignmentBounds);return s&&o},Bs=h.z.object({dpr:h.z.number(),region:r.box.box,bootstrap:h.z.boolean().default(!1),bootstrapped:h.z.boolean().default(!1),glCanvas:h.z.any().optional(),upper2dCanvas:h.z.any().optional(),lower2dCanvas:h.z.any().optional(),os:r.runtime.osZ});class Ht extends w.Composite{static TYPE="Canvas";schema=Bs;renderCtx=null;afterUpdate(e){if(this.renderCtx==null){if(!this.state.bootstrap)return;const{glCanvas:t,lower2dCanvas:s,upper2dCanvas:o,os:i}=this.state;if(t==null||s==null||o==null)throw new x.UnexpectedError("[vis.worker.Canvas] - expected render context bootstrap to include all canvases");this.renderCtx=I.Context.create(e,t,s,o,i),_e.create(e,this.renderCtx),this.setState(a=>({...a,bootstrap:!1,bootstrapped:!0,glCanvas:void 0,lower2dCanvas:void 0,upper2dCanvas:void 0}))}else this.renderCtx.update(e);this.renderCtx.resize(this.state.region,this.state.dpr)}}const Wo={[Ht.TYPE]:Ht},Bl=Object.freeze(Object.defineProperty({__proto__:null,Canvas:Ht,REGISTRY:Wo,canvasStateZ:Bs},Symbol.toStringTag,{value:"Module"})),Fs=h.z.object({position:r.xy.xy,zoom:h.z.number(),region:r.box.box,clearOverScan:r.xy.crudeZ.default(5),visible:h.z.boolean().default(!0),autoRenderInterval:h.z.number().optional()}),vt=["upper2d","lower2d"];class xe extends w.Composite{static TYPE="Diagram";static stateZ=Fs;schema=xe.stateZ;afterUpdate(e){this.internal.renderCtx=I.Context.use(e),this.internal.handleError=w.useErrorHandler(e),r.primitive.isNonZero(this.state.autoRenderInterval)&&(this.internal.autoRenderInterval??=setInterval(()=>{this.state.visible&&this.requestRender("low")},this.state.autoRenderInterval)),on(e,()=>{this.state.visible&&this.requestRender("low")}),!(!this.state.visible&&!this.prevState.visible)&&(this.internal.viewportScale=r.scale.XY.magnify(r.xy.construct(this.state.zoom)).translate(r.box.topLeft(this.state.region)).translate(this.state.position),this.requestRender("high"))}afterDelete(){this.internal.autoRenderInterval!=null&&clearInterval(this.internal.autoRenderInterval),this.requestRender("high")}render(){if(this.deleted)return;const{renderCtx:e,handleError:t,viewportScale:s}=this.internal,o=r.box.construct(this.state.region);if(!this.state.visible)return()=>e.erase(o,this.state.clearOverScan,...vt);const i=e.scissor(o,r.xy.ZERO,vt);try{this.children.forEach(l=>l.render?.({viewportScale:s}))}catch(l){t(l,"failed to render diagram")}finally{i()}const a=r.box.copy(this.state.region);return()=>{e.lower2d.fillStyle=r.color.hex(r.color.BLACK),e.lower2d.fillRect(...r.xy.couple(r.box.topLeft(a)),r.box.width(a),r.box.height(a)),e.erase(a,this.state.clearOverScan,...vt)}}requestRender(e){const{renderCtx:t}=this.internal;t.loop.set({key:`${xe.TYPE}-${this.key}`,render:this.render.bind(this),priority:e,canvases:vt})}}const Vo={[xe.TYPE]:xe},Fl=Object.freeze(Object.defineProperty({__proto__:null,Diagram:xe,REGISTRY:Vo,diagramStateZ:Fs},Symbol.toStringTag,{value:"Module"}));function Lt(n,e){return n==null||e==null?NaN:n<e?-1:n>e?1:n>=e?0:NaN}function $l(n,e){return n==null||e==null?NaN:e<n?-1:e>n?1:e>=n?0:NaN}function $s(n){let e,t,s;n.length!==2?(e=Lt,t=(l,u)=>Lt(n(l),u),s=(l,u)=>n(l)-u):(e=n===Lt||n===$l?n:Hl,t=n,s=n);function o(l,u,c=0,d=l.length){if(c<d){if(e(u,u)!==0)return d;do{const f=c+d>>>1;t(l[f],u)<0?c=f+1:d=f}while(c<d)}return c}function i(l,u,c=0,d=l.length){if(c<d){if(e(u,u)!==0)return d;do{const f=c+d>>>1;t(l[f],u)<=0?c=f+1:d=f}while(c<d)}return c}function a(l,u,c=0,d=l.length){const f=o(l,u,c,d-1);return f>c&&s(l[f-1],u)>-s(l[f],u)?f-1:f}return{left:o,center:a,right:i}}function Hl(){return 0}function ql(n){return n===null?NaN:+n}const jl=$s(Lt),Wl=jl.right;$s(ql).center;const Vl=Math.sqrt(50),Xl=Math.sqrt(10),Gl=Math.sqrt(2);function qt(n,e,t){const s=(e-n)/Math.max(0,t),o=Math.floor(Math.log10(s)),i=s/Math.pow(10,o),a=i>=Vl?10:i>=Xl?5:i>=Gl?2:1;let l,u,c;return o<0?(c=Math.pow(10,-o)/a,l=Math.round(n*c),u=Math.round(e*c),l/c<n&&++l,u/c>e&&--u,c=-c):(c=Math.pow(10,o)*a,l=Math.round(n/c),u=Math.round(e/c),l*c<n&&++l,u*c>e&&--u),u<l&&.5<=t&&t<2?qt(n,e,t*2):[l,u,c]}function Kl(n,e,t){if(e=+e,n=+n,t=+t,!(t>0))return[];if(n===e)return[n];const s=e<n,[o,i,a]=s?qt(e,n,t):qt(n,e,t);if(!(i>=o))return[];const l=i-o+1,u=new Array(l);if(s)if(a<0)for(let c=0;c<l;++c)u[c]=(i-c)/-a;else for(let c=0;c<l;++c)u[c]=(i-c)*a;else if(a<0)for(let c=0;c<l;++c)u[c]=(o+c)/-a;else for(let c=0;c<l;++c)u[c]=(o+c)*a;return u}function Vn(n,e,t){return e=+e,n=+n,t=+t,qt(n,e,t)[2]}function Xn(n,e,t){e=+e,n=+n,t=+t;const s=e<n,o=s?Vn(e,n,t):Vn(n,e,t);return(s?-1:1)*(o<0?1/-o:o)}function Xo(n,e){switch(arguments.length){case 0:break;case 1:this.range(n);break;default:this.range(e).domain(n);break}return this}function Ql(n){return function(){return n}}function Jl(n){return+n}var gr=[0,1];function Pe(n){return n}function Gn(n,e){return(e-=n=+n)?function(t){return(t-n)/e}:Ql(isNaN(e)?NaN:.5)}function ec(n,e){var t;return n>e&&(t=n,n=e,e=t),function(s){return Math.max(n,Math.min(e,s))}}function tc(n,e,t){var s=n[0],o=n[1],i=e[0],a=e[1];return o<s?(s=Gn(o,s),i=t(a,i)):(s=Gn(s,o),i=t(i,a)),function(l){return i(s(l))}}function nc(n,e,t){var s=Math.min(n.length,e.length)-1,o=new Array(s),i=new Array(s),a=-1;for(n[s]<n[0]&&(n=n.slice().reverse(),e=e.slice().reverse());++a<s;)o[a]=Gn(n[a],n[a+1]),i[a]=t(e[a],e[a+1]);return function(l){var u=Wl(n,l,1,s)-1;return i[u](o[u](l))}}function Go(n,e){return e.domain(n.domain()).range(n.range()).interpolate(n.interpolate()).clamp(n.clamp()).unknown(n.unknown())}function sc(){var n=gr,e=gr,t=ln,s,o,i,a=Pe,l,u,c;function d(){var p=Math.min(n.length,e.length);return a!==Pe&&(a=ec(n[0],n[p-1])),l=p>2?nc:tc,u=c=null,f}function f(p){return p==null||isNaN(p=+p)?i:(u||(u=l(n.map(s),e,t)))(s(a(p)))}return f.invert=function(p){return a(o((c||(c=l(e,n.map(s),nt)))(p)))},f.domain=function(p){return arguments.length?(n=Array.from(p,Jl),d()):n.slice()},f.range=function(p){return arguments.length?(e=Array.from(p),d()):e.slice()},f.rangeRound=function(p){return e=Array.from(p),t=Ia,d()},f.clamp=function(p){return arguments.length?(a=p?!0:Pe,d()):a!==Pe},f.interpolate=function(p){return arguments.length?(t=p,d()):t},f.unknown=function(p){return arguments.length?(i=p,f):i},function(p,g){return s=p,o=g,d()}}function Ko(){return sc()(Pe,Pe)}function rc(n){return Math.abs(n=Math.round(n))>=1e21?n.toLocaleString("en").replace(/,/g,""):n.toString(10)}function jt(n,e){if(!isFinite(n)||n===0)return null;var t=(n=e?n.toExponential(e-1):n.toExponential()).indexOf("e"),s=n.slice(0,t);return[s.length>1?s[0]+s.slice(2):s,+n.slice(t+1)]}function Ze(n){return n=jt(Math.abs(n)),n?n[1]:NaN}function oc(n,e){return function(t,s){for(var o=t.length,i=[],a=0,l=n[0],u=0;o>0&&l>0&&(u+l+1>s&&(l=Math.max(1,s-u)),i.push(t.substring(o-=l,o+l)),!((u+=l+1)>s));)l=n[a=(a+1)%n.length];return i.reverse().join(e)}}function ic(n){return function(e){return e.replace(/[0-9]/g,function(t){return n[+t]})}}var ac=/^(?:(.)?([<>=^]))?([+\-( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;function Wt(n){if(!(e=ac.exec(n)))throw new Error("invalid format: "+n);var e;return new Hs({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]})}Wt.prototype=Hs.prototype;function Hs(n){this.fill=n.fill===void 0?" ":n.fill+"",this.align=n.align===void 0?">":n.align+"",this.sign=n.sign===void 0?"-":n.sign+"",this.symbol=n.symbol===void 0?"":n.symbol+"",this.zero=!!n.zero,this.width=n.width===void 0?void 0:+n.width,this.comma=!!n.comma,this.precision=n.precision===void 0?void 0:+n.precision,this.trim=!!n.trim,this.type=n.type===void 0?"":n.type+""}Hs.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 lc(n){e:for(var e=n.length,t=1,s=-1,o;t<e;++t)switch(n[t]){case".":s=o=t;break;case"0":s===0&&(s=t),o=t;break;default:if(!+n[t])break e;s>0&&(s=0);break}return s>0?n.slice(0,s)+n.slice(o+1):n}var Vt;function cc(n,e){var t=jt(n,e);if(!t)return Vt=void 0,n.toPrecision(e);var s=t[0],o=t[1],i=o-(Vt=Math.max(-8,Math.min(8,Math.floor(o/3)))*3)+1,a=s.length;return i===a?s:i>a?s+new Array(i-a+1).join("0"):i>0?s.slice(0,i)+"."+s.slice(i):"0."+new Array(1-i).join("0")+jt(n,Math.max(0,e+i-1))[0]}function yr(n,e){var t=jt(n,e);if(!t)return n+"";var s=t[0],o=t[1];return o<0?"0."+new Array(-o).join("0")+s:s.length>o+1?s.slice(0,o+1)+"."+s.slice(o+1):s+new Array(o-s.length+2).join("0")}const xr={"%":(n,e)=>(n*100).toFixed(e),b:n=>Math.round(n).toString(2),c:n=>n+"",d:rc,e:(n,e)=>n.toExponential(e),f:(n,e)=>n.toFixed(e),g:(n,e)=>n.toPrecision(e),o:n=>Math.round(n).toString(8),p:(n,e)=>yr(n*100,e),r:yr,s:cc,X:n=>Math.round(n).toString(16).toUpperCase(),x:n=>Math.round(n).toString(16)};function br(n){return n}var Sr=Array.prototype.map,Tr=["y","z","a","f","p","n","µ","m","","k","M","G","T","P","E","Z","Y"];function uc(n){var e=n.grouping===void 0||n.thousands===void 0?br:oc(Sr.call(n.grouping,Number),n.thousands+""),t=n.currency===void 0?"":n.currency[0]+"",s=n.currency===void 0?"":n.currency[1]+"",o=n.decimal===void 0?".":n.decimal+"",i=n.numerals===void 0?br:ic(Sr.call(n.numerals,String)),a=n.percent===void 0?"%":n.percent+"",l=n.minus===void 0?"−":n.minus+"",u=n.nan===void 0?"NaN":n.nan+"";function c(f,p){f=Wt(f);var g=f.fill,T=f.align,y=f.sign,v=f.symbol,R=f.zero,L=f.width,k=f.comma,C=f.precision,Z=f.trim,b=f.type;b==="n"?(k=!0,b="g"):xr[b]||(C===void 0&&(C=12),Z=!0,b="g"),(R||g==="0"&&T==="=")&&(R=!0,g="0",T="=");var M=(p&&p.prefix!==void 0?p.prefix:"")+(v==="$"?t:v==="#"&&/[boxX]/.test(b)?"0"+b.toLowerCase():""),A=(v==="$"?s:/[%p]/.test(b)?a:"")+(p&&p.suffix!==void 0?p.suffix:""),V=xr[b],K=/[defgprs%]/.test(b);C=C===void 0?6:/[gprs]/.test(b)?Math.max(1,Math.min(21,C)):Math.max(0,Math.min(20,C));function ue(E){var $=M,N=A,Q,de,ne;if(b==="c")N=V(E)+N,E="";else{E=+E;var J=E<0||1/E<0;if(E=isNaN(E)?u:V(Math.abs(E),C),Z&&(E=lc(E)),J&&+E==0&&y!=="+"&&(J=!1),$=(J?y==="("?y:l:y==="-"||y==="("?"":y)+$,N=(b==="s"&&!isNaN(E)&&Vt!==void 0?Tr[8+Vt/3]:"")+N+(J&&y==="("?")":""),K){for(Q=-1,de=E.length;++Q<de;)if(ne=E.charCodeAt(Q),48>ne||ne>57){N=(ne===46?o+E.slice(Q+1):E.slice(Q))+N,E=E.slice(0,Q);break}}}k&&!R&&(E=e(E,1/0));var se=$.length+E.length+N.length,H=se<L?new Array(L-se+1).join(g):"";switch(k&&R&&(E=e(H+E,H.length?L-N.length:1/0),H=""),T){case"<":E=$+E+N+H;break;case"=":E=$+H+E+N;break;case"^":E=H.slice(0,se=H.length>>1)+$+E+N+H.slice(se);break;default:E=H+$+E+N;break}return i(E)}return ue.toString=function(){return f+""},ue}function d(f,p){var g=Math.max(-8,Math.min(8,Math.floor(Ze(p)/3)))*3,T=Math.pow(10,-g),y=c((f=Wt(f),f.type="f",f),{suffix:Tr[8+g/3]});return function(v){return y(T*v)}}return{format:c,formatPrefix:d}}var wt,Qo,Jo;hc({thousands:",",grouping:[3],currency:["$",""]});function hc(n){return wt=uc(n),Qo=wt.format,Jo=wt.formatPrefix,wt}function dc(n){return Math.max(0,-Ze(Math.abs(n)))}function fc(n,e){return Math.max(0,Math.max(-8,Math.min(8,Math.floor(Ze(e)/3)))*3-Ze(Math.abs(n)))}function pc(n,e){return n=Math.abs(n),e=Math.abs(e)-n,Math.max(0,Ze(e)-Ze(n))+1}function mc(n,e,t,s){var o=Xn(n,e,t),i;switch(s=Wt(s??",f"),s.type){case"s":{var a=Math.max(Math.abs(n),Math.abs(e));return s.precision==null&&!isNaN(i=fc(o,a))&&(s.precision=i),Jo(s,a)}case"":case"e":case"g":case"p":case"r":{s.precision==null&&!isNaN(i=pc(o,Math.max(Math.abs(n),Math.abs(e))))&&(s.precision=i-(s.type==="e"));break}case"f":case"%":{s.precision==null&&!isNaN(i=dc(o))&&(s.precision=i-(s.type==="%")*2);break}}return Qo(s)}function gc(n){var e=n.domain;return n.ticks=function(t){var s=e();return Kl(s[0],s[s.length-1],t??10)},n.tickFormat=function(t,s){var o=e();return mc(o[0],o[o.length-1],t??10,s)},n.nice=function(t){t==null&&(t=10);var s=e(),o=0,i=s.length-1,a=s[o],l=s[i],u,c,d=10;for(l<a&&(c=a,a=l,l=c,c=o,o=i,i=c);d-- >0;){if(c=Vn(a,l,t),c===u)return s[o]=a,s[i]=l,e(s);if(c>0)a=Math.floor(a/c)*c,l=Math.ceil(l/c)*c;else if(c<0)a=Math.ceil(a*c)/c,l=Math.floor(l*c)/c;else break;u=c}return n},n}function ei(){var n=Ko();return n.copy=function(){return Go(n,ei())},Xo.apply(n,arguments),gc(n)}function yc(n,e){n=n.slice();var t=0,s=n.length-1,o=n[t],i=n[s],a;return i<o&&(a=t,t=s,s=a,a=o,o=i,i=a),n[t]=e.floor(o),n[s]=e.ceil(i),n}const Pn=new Date,Ln=new Date;function z(n,e,t,s){function o(i){return n(i=arguments.length===0?new Date:new Date(+i)),i}return o.floor=i=>(n(i=new Date(+i)),i),o.ceil=i=>(n(i=new Date(i-1)),e(i,1),n(i),i),o.round=i=>{const a=o(i),l=o.ceil(i);return i-a<l-i?a:l},o.offset=(i,a)=>(e(i=new Date(+i),a==null?1:Math.floor(a)),i),o.range=(i,a,l)=>{const u=[];if(i=o.ceil(i),l=l==null?1:Math.floor(l),!(i<a)||!(l>0))return u;let c;do u.push(c=new Date(+i)),e(i,l),n(i);while(c<i&&i<a);return u},o.filter=i=>z(a=>{if(a>=a)for(;n(a),!i(a);)a.setTime(a-1)},(a,l)=>{if(a>=a)if(l<0)for(;++l<=0;)for(;e(a,-1),!i(a););else for(;--l>=0;)for(;e(a,1),!i(a););}),t&&(o.count=(i,a)=>(Pn.setTime(+i),Ln.setTime(+a),n(Pn),n(Ln),Math.floor(t(Pn,Ln))),o.every=i=>(i=Math.floor(i),!isFinite(i)||!(i>0)?null:i>1?o.filter(s?a=>s(a)%i===0:a=>o.count(0,a)%i===0):o)),o}const Xt=z(()=>{},(n,e)=>{n.setTime(+n+e)},(n,e)=>e-n);Xt.every=n=>(n=Math.floor(n),!isFinite(n)||!(n>0)?null:n>1?z(e=>{e.setTime(Math.floor(e/n)*n)},(e,t)=>{e.setTime(+e+t*n)},(e,t)=>(t-e)/n):Xt);Xt.range;const re=1e3,X=re*60,oe=X*60,ae=oe*24,qs=ae*7,vr=ae*30,kn=ae*365,Le=z(n=>{n.setTime(n-n.getMilliseconds())},(n,e)=>{n.setTime(+n+e*re)},(n,e)=>(e-n)/re,n=>n.getUTCSeconds());Le.range;const js=z(n=>{n.setTime(n-n.getMilliseconds()-n.getSeconds()*re)},(n,e)=>{n.setTime(+n+e*X)},(n,e)=>(e-n)/X,n=>n.getMinutes());js.range;const xc=z(n=>{n.setUTCSeconds(0,0)},(n,e)=>{n.setTime(+n+e*X)},(n,e)=>(e-n)/X,n=>n.getUTCMinutes());xc.range;const Ws=z(n=>{n.setTime(n-n.getMilliseconds()-n.getSeconds()*re-n.getMinutes()*X)},(n,e)=>{n.setTime(+n+e*oe)},(n,e)=>(e-n)/oe,n=>n.getHours());Ws.range;const bc=z(n=>{n.setUTCMinutes(0,0,0)},(n,e)=>{n.setTime(+n+e*oe)},(n,e)=>(e-n)/oe,n=>n.getUTCHours());bc.range;const gt=z(n=>n.setHours(0,0,0,0),(n,e)=>n.setDate(n.getDate()+e),(n,e)=>(e-n-(e.getTimezoneOffset()-n.getTimezoneOffset())*X)/ae,n=>n.getDate()-1);gt.range;const Vs=z(n=>{n.setUTCHours(0,0,0,0)},(n,e)=>{n.setUTCDate(n.getUTCDate()+e)},(n,e)=>(e-n)/ae,n=>n.getUTCDate()-1);Vs.range;const Sc=z(n=>{n.setUTCHours(0,0,0,0)},(n,e)=>{n.setUTCDate(n.getUTCDate()+e)},(n,e)=>(e-n)/ae,n=>Math.floor(n/ae));Sc.range;function Te(n){return z(e=>{e.setDate(e.getDate()-(e.getDay()+7-n)%7),e.setHours(0,0,0,0)},(e,t)=>{e.setDate(e.getDate()+t*7)},(e,t)=>(t-e-(t.getTimezoneOffset()-e.getTimezoneOffset())*X)/qs)}const yn=Te(0),Gt=Te(1),Tc=Te(2),vc=Te(3),Ue=Te(4),wc=Te(5),Ec=Te(6);yn.range;Gt.range;Tc.range;vc.range;Ue.range;wc.range;Ec.range;function ve(n){return z(e=>{e.setUTCDate(e.getUTCDate()-(e.getUTCDay()+7-n)%7),e.setUTCHours(0,0,0,0)},(e,t)=>{e.setUTCDate(e.getUTCDate()+t*7)},(e,t)=>(t-e)/qs)}const ti=ve(0),Kt=ve(1),Cc=ve(2),Rc=ve(3),Be=ve(4),Pc=ve(5),Lc=ve(6);ti.range;Kt.range;Cc.range;Rc.range;Be.range;Pc.range;Lc.range;const Xs=z(n=>{n.setDate(1),n.setHours(0,0,0,0)},(n,e)=>{n.setMonth(n.getMonth()+e)},(n,e)=>e.getMonth()-n.getMonth()+(e.getFullYear()-n.getFullYear())*12,n=>n.getMonth());Xs.range;const kc=z(n=>{n.setUTCDate(1),n.setUTCHours(0,0,0,0)},(n,e)=>{n.setUTCMonth(n.getUTCMonth()+e)},(n,e)=>e.getUTCMonth()-n.getUTCMonth()+(e.getUTCFullYear()-n.getUTCFullYear())*12,n=>n.getUTCMonth());kc.range;const le=z(n=>{n.setMonth(0,1),n.setHours(0,0,0,0)},(n,e)=>{n.setFullYear(n.getFullYear()+e)},(n,e)=>e.getFullYear()-n.getFullYear(),n=>n.getFullYear());le.every=n=>!isFinite(n=Math.floor(n))||!(n>0)?null:z(e=>{e.setFullYear(Math.floor(e.getFullYear()/n)*n),e.setMonth(0,1),e.setHours(0,0,0,0)},(e,t)=>{e.setFullYear(e.getFullYear()+t*n)});le.range;const be=z(n=>{n.setUTCMonth(0,1),n.setUTCHours(0,0,0,0)},(n,e)=>{n.setUTCFullYear(n.getUTCFullYear()+e)},(n,e)=>e.getUTCFullYear()-n.getUTCFullYear(),n=>n.getUTCFullYear());be.every=n=>!isFinite(n=Math.floor(n))||!(n>0)?null:z(e=>{e.setUTCFullYear(Math.floor(e.getUTCFullYear()/n)*n),e.setUTCMonth(0,1),e.setUTCHours(0,0,0,0)},(e,t)=>{e.setUTCFullYear(e.getUTCFullYear()+t*n)});be.range;function _c(n,e,t,s,o,i){const a=[[Le,1,re],[Le,5,5*re],[Le,15,15*re],[Le,30,30*re],[i,1,X],[i,5,5*X],[i,15,15*X],[i,30,30*X],[o,1,oe],[o,3,3*oe],[o,6,6*oe],[o,12,12*oe],[s,1,ae],[s,2,2*ae],[t,1,qs],[e,1,vr],[e,3,3*vr],[n,1,kn]];function l(c,d,f){const p=d<c;p&&([c,d]=[d,c]);const g=f&&typeof f.range=="function"?f:u(c,d,f),T=g?g.range(c,+d+1):[];return p?T.reverse():T}function u(c,d,f){const p=Math.abs(d-c)/f,g=$s(([,,v])=>v).right(a,p);if(g===a.length)return n.every(Xn(c/kn,d/kn,f));if(g===0)return Xt.every(Math.max(Xn(c,d,f),1));const[T,y]=a[p/a[g-1][2]<a[g][2]/p?g-1:g];return T.every(y)}return[l,u]}const[Oc,Mc]=_c(le,Xs,yn,gt,Ws,js);function _n(n){if(0<=n.y&&n.y<100){var e=new Date(-1,n.m,n.d,n.H,n.M,n.S,n.L);return e.setFullYear(n.y),e}return new Date(n.y,n.m,n.d,n.H,n.M,n.S,n.L)}function On(n){if(0<=n.y&&n.y<100){var e=new Date(Date.UTC(-1,n.m,n.d,n.H,n.M,n.S,n.L));return e.setUTCFullYear(n.y),e}return new Date(Date.UTC(n.y,n.m,n.d,n.H,n.M,n.S,n.L))}function je(n,e,t){return{y:n,m:e,d:t,H:0,M:0,S:0,L:0}}function Dc(n){var e=n.dateTime,t=n.date,s=n.time,o=n.periods,i=n.days,a=n.shortDays,l=n.months,u=n.shortMonths,c=We(o),d=Ve(o),f=We(i),p=Ve(i),g=We(a),T=Ve(a),y=We(l),v=Ve(l),R=We(u),L=Ve(u),k={a:ne,A:J,b:se,B:H,c:null,d:Lr,e:Lr,f:nu,g:du,G:pu,H:Jc,I:eu,j:tu,L:ni,m:su,M:ru,p:xn,q:bn,Q:Or,s:Mr,S:ou,u:iu,U:au,V:lu,w:cu,W:uu,x:null,X:null,y:hu,Y:fu,Z:mu,"%":_r},C={a:Sn,A:Tn,b:vn,B:bt,c:null,d:kr,e:kr,f:bu,g:ku,G:Ou,H:gu,I:yu,j:xu,L:ri,m:Su,M:Tu,p:wn,q:qi,Q:Or,s:Mr,S:vu,u:wu,U:Eu,V:Cu,w:Ru,W:Pu,x:null,X:null,y:Lu,Y:_u,Z:Mu,"%":_r},Z={a:K,A:ue,b:E,B:$,c:N,d:Rr,e:Rr,f:Xc,g:Cr,G:Er,H:Pr,I:Pr,j:qc,L:Vc,m:Hc,M:jc,p:V,q:$c,Q:Kc,s:Qc,S:Wc,u:Nc,U:Zc,V:Uc,w:Yc,W:Bc,x:Q,X:de,y:Cr,Y:Er,Z:Fc,"%":Gc};k.x=b(t,k),k.X=b(s,k),k.c=b(e,k),C.x=b(t,C),C.X=b(s,C),C.c=b(e,C);function b(S,P){return function(_){var m=[],B=-1,D=0,q=S.length,j,fe,nr;for(_ instanceof Date||(_=new Date(+_));++B<q;)S.charCodeAt(B)===37&&(m.push(S.slice(D,B)),(fe=wr[j=S.charAt(++B)])!=null?j=S.charAt(++B):fe=j==="e"?" ":"0",(nr=P[j])&&(j=nr(_,fe)),m.push(j),D=B+1);return m.push(S.slice(D,B)),m.join("")}}function M(S,P){return function(_){var m=je(1900,void 0,1),B=A(m,S,_+="",0),D,q;if(B!=_.length)return null;if("Q"in m)return new Date(m.Q);if("s"in m)return new Date(m.s*1e3+("L"in m?m.L:0));if(P&&!("Z"in m)&&(m.Z=0),"p"in m&&(m.H=m.H%12+m.p*12),m.m===void 0&&(m.m="q"in m?m.q:0),"V"in m){if(m.V<1||m.V>53)return null;"w"in m||(m.w=1),"Z"in m?(D=On(je(m.y,0,1)),q=D.getUTCDay(),D=q>4||q===0?Kt.ceil(D):Kt(D),D=Vs.offset(D,(m.V-1)*7),m.y=D.getUTCFullYear(),m.m=D.getUTCMonth(),m.d=D.getUTCDate()+(m.w+6)%7):(D=_n(je(m.y,0,1)),q=D.getDay(),D=q>4||q===0?Gt.ceil(D):Gt(D),D=gt.offset(D,(m.V-1)*7),m.y=D.getFullYear(),m.m=D.getMonth(),m.d=D.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),q="Z"in m?On(je(m.y,0,1)).getUTCDay():_n(je(m.y,0,1)).getDay(),m.m=0,m.d="W"in m?(m.w+6)%7+m.W*7-(q+5)%7:m.w+m.U*7-(q+6)%7);return"Z"in m?(m.H+=m.Z/100|0,m.M+=m.Z%100,On(m)):_n(m)}}function A(S,P,_,m){for(var B=0,D=P.length,q=_.length,j,fe;B<D;){if(m>=q)return-1;if(j=P.charCodeAt(B++),j===37){if(j=P.charAt(B++),fe=Z[j in wr?P.charAt(B++):j],!fe||(m=fe(S,_,m))<0)return-1}else if(j!=_.charCodeAt(m++))return-1}return m}function V(S,P,_){var m=c.exec(P.slice(_));return m?(S.p=d.get(m[0].toLowerCase()),_+m[0].length):-1}function K(S,P,_){var m=g.exec(P.slice(_));return m?(S.w=T.get(m[0].toLowerCase()),_+m[0].length):-1}function ue(S,P,_){var m=f.exec(P.slice(_));return m?(S.w=p.get(m[0].toLowerCase()),_+m[0].length):-1}function E(S,P,_){var m=R.exec(P.slice(_));return m?(S.m=L.get(m[0].toLowerCase()),_+m[0].length):-1}function $(S,P,_){var m=y.exec(P.slice(_));return m?(S.m=v.get(m[0].toLowerCase()),_+m[0].length):-1}function N(S,P,_){return A(S,e,P,_)}function Q(S,P,_){return A(S,t,P,_)}function de(S,P,_){return A(S,s,P,_)}function ne(S){return a[S.getDay()]}function J(S){return i[S.getDay()]}function se(S){return u[S.getMonth()]}function H(S){return l[S.getMonth()]}function xn(S){return o[+(S.getHours()>=12)]}function bn(S){return 1+~~(S.getMonth()/3)}function Sn(S){return a[S.getUTCDay()]}function Tn(S){return i[S.getUTCDay()]}function vn(S){return u[S.getUTCMonth()]}function bt(S){return l[S.getUTCMonth()]}function wn(S){return o[+(S.getUTCHours()>=12)]}function qi(S){return 1+~~(S.getUTCMonth()/3)}return{format:function(S){var P=b(S+="",k);return P.toString=function(){return S},P},parse:function(S){var P=M(S+="",!1);return P.toString=function(){return S},P},utcFormat:function(S){var P=b(S+="",C);return P.toString=function(){return S},P},utcParse:function(S){var P=M(S+="",!0);return P.toString=function(){return S},P}}}var wr={"-":"",_:" ",0:"0"},Y=/^\s*\d+/,Ac=/^%/,Ic=/[\\^$*+?|[\]().{}]/g;function O(n,e,t){var s=n<0?"-":"",o=(s?-n:n)+"",i=o.length;return s+(i<t?new Array(t-i+1).join(e)+o:o)}function zc(n){return n.replace(Ic,"\\$&")}function We(n){return new RegExp("^(?:"+n.map(zc).join("|")+")","i")}function Ve(n){return new Map(n.map((e,t)=>[e.toLowerCase(),t]))}function Yc(n,e,t){var s=Y.exec(e.slice(t,t+1));return s?(n.w=+s[0],t+s[0].length):-1}function Nc(n,e,t){var s=Y.exec(e.slice(t,t+1));return s?(n.u=+s[0],t+s[0].length):-1}function Zc(n,e,t){var s=Y.exec(e.slice(t,t+2));return s?(n.U=+s[0],t+s[0].length):-1}function Uc(n,e,t){var s=Y.exec(e.slice(t,t+2));return s?(n.V=+s[0],t+s[0].length):-1}function Bc(n,e,t){var s=Y.exec(e.slice(t,t+2));return s?(n.W=+s[0],t+s[0].length):-1}function Er(n,e,t){var s=Y.exec(e.slice(t,t+4));return s?(n.y=+s[0],t+s[0].length):-1}function Cr(n,e,t){var s=Y.exec(e.slice(t,t+2));return s?(n.y=+s[0]+(+s[0]>68?1900:2e3),t+s[0].length):-1}function Fc(n,e,t){var s=/^(Z)|([+-]\d\d)(?::?(\d\d))?/.exec(e.slice(t,t+6));return s?(n.Z=s[1]?0:-(s[2]+(s[3]||"00")),t+s[0].length):-1}function $c(n,e,t){var s=Y.exec(e.slice(t,t+1));return s?(n.q=s[0]*3-3,t+s[0].length):-1}function Hc(n,e,t){var s=Y.exec(e.slice(t,t+2));return s?(n.m=s[0]-1,t+s[0].length):-1}function Rr(n,e,t){var s=Y.exec(e.slice(t,t+2));return s?(n.d=+s[0],t+s[0].length):-1}function qc(n,e,t){var s=Y.exec(e.slice(t,t+3));return s?(n.m=0,n.d=+s[0],t+s[0].length):-1}function Pr(n,e,t){var s=Y.exec(e.slice(t,t+2));return s?(n.H=+s[0],t+s[0].length):-1}function jc(n,e,t){var s=Y.exec(e.slice(t,t+2));return s?(n.M=+s[0],t+s[0].length):-1}function Wc(n,e,t){var s=Y.exec(e.slice(t,t+2));return s?(n.S=+s[0],t+s[0].length):-1}function Vc(n,e,t){var s=Y.exec(e.slice(t,t+3));return s?(n.L=+s[0],t+s[0].length):-1}function Xc(n,e,t){var s=Y.exec(e.slice(t,t+6));return s?(n.L=Math.floor(s[0]/1e3),t+s[0].length):-1}function Gc(n,e,t){var s=Ac.exec(e.slice(t,t+1));return s?t+s[0].length:-1}function Kc(n,e,t){var s=Y.exec(e.slice(t));return s?(n.Q=+s[0],t+s[0].length):-1}function Qc(n,e,t){var s=Y.exec(e.slice(t));return s?(n.s=+s[0],t+s[0].length):-1}function Lr(n,e){return O(n.getDate(),e,2)}function Jc(n,e){return O(n.getHours(),e,2)}function eu(n,e){return O(n.getHours()%12||12,e,2)}function tu(n,e){return O(1+gt.count(le(n),n),e,3)}function ni(n,e){return O(n.getMilliseconds(),e,3)}function nu(n,e){return ni(n,e)+"000"}function su(n,e){return O(n.getMonth()+1,e,2)}function ru(n,e){return O(n.getMinutes(),e,2)}function ou(n,e){return O(n.getSeconds(),e,2)}function iu(n){var e=n.getDay();return e===0?7:e}function au(n,e){return O(yn.count(le(n)-1,n),e,2)}function si(n){var e=n.getDay();return e>=4||e===0?Ue(n):Ue.ceil(n)}function lu(n,e){return n=si(n),O(Ue.count(le(n),n)+(le(n).getDay()===4),e,2)}function cu(n){return n.getDay()}function uu(n,e){return O(Gt.count(le(n)-1,n),e,2)}function hu(n,e){return O(n.getFullYear()%100,e,2)}function du(n,e){return n=si(n),O(n.getFullYear()%100,e,2)}function fu(n,e){return O(n.getFullYear()%1e4,e,4)}function pu(n,e){var t=n.getDay();return n=t>=4||t===0?Ue(n):Ue.ceil(n),O(n.getFullYear()%1e4,e,4)}function mu(n){var e=n.getTimezoneOffset();return(e>0?"-":(e*=-1,"+"))+O(e/60|0,"0",2)+O(e%60,"0",2)}function kr(n,e){return O(n.getUTCDate(),e,2)}function gu(n,e){return O(n.getUTCHours(),e,2)}function yu(n,e){return O(n.getUTCHours()%12||12,e,2)}function xu(n,e){return O(1+Vs.count(be(n),n),e,3)}function ri(n,e){return O(n.getUTCMilliseconds(),e,3)}function bu(n,e){return ri(n,e)+"000"}function Su(n,e){return O(n.getUTCMonth()+1,e,2)}function Tu(n,e){return O(n.getUTCMinutes(),e,2)}function vu(n,e){return O(n.getUTCSeconds(),e,2)}function wu(n){var e=n.getUTCDay();return e===0?7:e}function Eu(n,e){return O(ti.count(be(n)-1,n),e,2)}function oi(n){var e=n.getUTCDay();return e>=4||e===0?Be(n):Be.ceil(n)}function Cu(n,e){return n=oi(n),O(Be.count(be(n),n)+(be(n).getUTCDay()===4),e,2)}function Ru(n){return n.getUTCDay()}function Pu(n,e){return O(Kt.count(be(n)-1,n),e,2)}function Lu(n,e){return O(n.getUTCFullYear()%100,e,2)}function ku(n,e){return n=oi(n),O(n.getUTCFullYear()%100,e,2)}function _u(n,e){return O(n.getUTCFullYear()%1e4,e,4)}function Ou(n,e){var t=n.getUTCDay();return n=t>=4||t===0?Be(n):Be.ceil(n),O(n.getUTCFullYear()%1e4,e,4)}function Mu(){return"+0000"}function _r(){return"%"}function Or(n){return+n}function Mr(n){return Math.floor(+n/1e3)}var Ce,ii;Du({dateTime:"%x, %X",date:"%-m/%-d/%Y",time:"%-I:%M:%S %p",periods:["AM","PM"],days:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],shortDays:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],months:["January","February","March","April","May","June","July","August","September","October","November","December"],shortMonths:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]});function Du(n){return Ce=Dc(n),ii=Ce.format,Ce.parse,Ce.utcFormat,Ce.utcParse,Ce}function Au(n){return new Date(n)}function Iu(n){return n instanceof Date?+n:+new Date(+n)}function ai(n,e,t,s,o,i,a,l,u,c){var d=Ko(),f=d.invert,p=d.domain,g=c(".%L"),T=c(":%S"),y=c("%I:%M"),v=c("%I %p"),R=c("%a %d"),L=c("%b %d"),k=c("%B"),C=c("%Y");function Z(b){return(u(b)<b?g:l(b)<b?T:a(b)<b?y:i(b)<b?v:s(b)<b?o(b)<b?R:L:t(b)<b?k:C)(b)}return d.invert=function(b){return new Date(f(b))},d.domain=function(b){return arguments.length?p(Array.from(b,Iu)):p().map(Au)},d.ticks=function(b){var M=p();return n(M[0],M[M.length-1],b??10)},d.tickFormat=function(b,M){return M==null?Z:c(M)},d.nice=function(b){var M=p();return(!b||typeof b.range!="function")&&(b=e(M[0],M[M.length-1],b??10)),b?p(yc(M,b)):d},d.copy=function(){return Go(d,ai(n,e,t,s,o,i,a,l,u,c))},d}function zu(){return Xo.apply(ai(Oc,Mc,le,Xs,yn,gt,Ws,js,Le,ii).domain([new Date(2e3,0,1),new Date(2e3,0,2)]),arguments)}const Dr=[r.TimeSpan.NANOSECOND,r.TimeSpan.nanoseconds(2),r.TimeSpan.nanoseconds(5),r.TimeSpan.nanoseconds(10),r.TimeSpan.nanoseconds(20),r.TimeSpan.nanoseconds(50),r.TimeSpan.nanoseconds(100),r.TimeSpan.nanoseconds(200),r.TimeSpan.nanoseconds(500),r.TimeSpan.MICROSECOND,r.TimeSpan.microseconds(2),r.TimeSpan.microseconds(5),r.TimeSpan.microseconds(10),r.TimeSpan.microseconds(20),r.TimeSpan.microseconds(50),r.TimeSpan.microseconds(100),r.TimeSpan.microseconds(200),r.TimeSpan.microseconds(500),r.TimeSpan.MILLISECOND,r.TimeSpan.milliseconds(2),r.TimeSpan.milliseconds(5),r.TimeSpan.milliseconds(10),r.TimeSpan.milliseconds(20),r.TimeSpan.milliseconds(50),r.TimeSpan.milliseconds(100),r.TimeSpan.milliseconds(200),r.TimeSpan.milliseconds(500),r.TimeSpan.SECOND];class Yu{_domain;_range;_span;constructor(){this._domain=[new r.TimeStamp(0n),new r.TimeStamp(1n)],this._range=[0,1],this._span=this._domain[1].span(this._domain[0])}domain(e){return e===void 0?this._domain:(this._domain=[new r.TimeStamp(e[0]),new r.TimeStamp(e[1])],this._span=this._domain[1].span(this._domain[0]),this)}range(e){return e===void 0?this._range:(this._range=e,this)}scale(e){const s=new r.TimeStamp(e).valueOf(),o=this._domain[0].valueOf(),i=this._domain[1].valueOf()-o,a=this._range[1]-this._range[0];return Number(s-o)/Number(i)*a+this._range[0]}ticks(e){const t=this.calculateOptimalStep(e).valueOf(),s=this._domain[0].valueOf(),o=this._domain[1].valueOf(),i=(s+t-1n)/t*t,a=Number((o-i)/t);return Array.from({length:a+1},(l,u)=>{const c=i+BigInt(u)*t;return new r.TimeStamp(c)}).filter(l=>l.afterEq(this._domain[0])&&l.beforeEq(this._domain[1]))}calculateOptimalStep(e){const t=this._span.valueOf()/BigInt(Math.ceil(e));let s=Dr[0];for(const o of Dr){if(o.valueOf()>t)break;s=o}return s}formatTick(e){return this._span.lessThan(r.TimeSpan.microseconds(50))?`${e.remainder(r.TimeSpan.MILLISECOND).microseconds.toString()}µs`:`${e.remainder(r.TimeSpan.SECOND).milliseconds.toString()}ms`}}const Nu=()=>new Yu,Gs=h.z.enum(["linear","time"]),Ks=h.z.object({tickSpacing:h.z.number().default(75),type:Gs.default("linear")}),Kn=n=>{const e=Ks.parse(n);return Bu[e.type](e)};class Zu{props;prevScaleSize;prevDomain;currTicks;normalScale;preciseScale;constructor(e){this.props=e,this.normalScale=zu(),this.preciseScale=Nu(),this.prevScaleSize=0,this.prevDomain=new r.TimeRange(new r.TimeStamp(0),new r.TimeStamp(0)),this.currTicks=[]}create({decimalToDataScale:e,size:t}){const s=new r.TimeRange(new r.TimeStamp(e.pos(0)),new r.TimeStamp(e.pos(1)));if(this.prevDomain.equals(s)&&this.prevScaleSize===t)return this.currTicks;if(this.prevDomain=s,this.prevScaleSize!==t){const o=[0,t];this.preciseScale.range(o),this.normalScale.range(o),this.prevScaleSize=t}if(s.span.milliseconds<5){this.preciseScale.domain([s.start,s.end]);const o=Qn(t,this.props.tickSpacing)/2,i=this.preciseScale.ticks(o);this.currTicks=i.map(a=>({label:this.preciseScale.formatTick(a),position:this.preciseScale.scale(a)}))}else{this.normalScale.domain([s.start.date(),s.end.date()]);const o=this.normalScale.ticks(Qn(t,this.props.tickSpacing));this.currTicks=o.map(i=>({label:this.normalTickLabel(i),position:this.normalScale(i)}))}return this.currTicks}normalTickLabel(e){let t=`:${e.getSeconds()}`;const s=e.getMilliseconds();if(s!==0){const o=Math.round(e.getMilliseconds()).toString().padStart(3,"0").replace(/0+$/,"");t+=`.${o}`}return e.getSeconds()===0&&s===0&&(t=`${e.getHours()}:${e.getMinutes().toString().padStart(2,"0")}`),t}}class Uu{props;prevDomain;prevScaleSize;currTicks;d3Scale;constructor(e){this.props=e,this.prevDomain=r.bounds.construct(0,0),this.prevScaleSize=0,this.currTicks=[],this.d3Scale=ei()}create({decimalToDataScale:e,size:t}){const s={lower:e.pos(0),upper:e.pos(1)};if(r.bounds.equals(this.prevDomain,s)&&this.prevScaleSize===t)return this.currTicks;r.bounds.equals(this.prevDomain,s)||(this.d3Scale=this.d3Scale.domain([s.lower,s.upper])),this.prevScaleSize!==t&&(this.d3Scale=this.d3Scale.range([0,t])),this.prevDomain=s,this.prevScaleSize=t;const o=Qn(t,this.props.tickSpacing),i=this.d3Scale.ticks(o);return this.currTicks=i.map(a=>({label:this.tickLabel(a),position:this.d3Scale(a)})),this.currTicks}tickLabel(e){return e.toString()}}const Qn=(n,e)=>{const t=Math.floor(n/e);return t>0?t:1},Bu={linear:n=>new Uu(n),time:n=>new Zu(n)},Qs=Ks.extend({color:r.color.colorZ,type:Gs.default("linear"),font:h.z.string(),showGrid:h.z.boolean().default(!0),location:r.location.outer,gridColor:r.color.colorZ}),G=5,rt=6,yt={useAtlas:!0},Fu={bottom:(n,e)=>new ci(n,e),top:(n,e)=>new ui(n,e),left:(n,e)=>new $u(n,e),right:(n,e)=>new hi(n,e)},li=(n,e,t)=>Fu[n](e,t);class we{renderCtx;state;tickFactory;constructor(e,t){this.renderCtx=e,this.state=t,this.tickFactory=Kn(this.state)}setState(e){this.state=w.prettyParse(Qs,e),this.tickFactory=Kn(e)}drawLine(e,t){const{lower2d:s}=this.renderCtx;s.moveTo(...r.xy.couple(e)),s.lineTo(...r.xy.couple(t))}drawTicks(e,t){let s=r.dimensions.ZERO;return e.forEach(o=>{const i=this.renderCtx.lower2d.textDimensions(o.label,yt);s=r.dimensions.max([s,i]),t(i,o)}),s}static START_BOUND=r.bounds.construct(-1,1);maybeDrawGrid(e,t,s){const{showGrid:o,gridColor:i}=this.state;if(o){const a=we.START_BOUND,l=r.bounds.construct(e-1,e+1),{lower2d:u}=this.renderCtx;u.beginPath(),u.strokeStyle=r.color.hex(i),t.forEach(c=>{r.bounds.contains(a,c.position)||r.bounds.contains(l,c.position)||this.drawLine(...s(c))}),u.stroke()}}setColor(e){const t=r.color.hex(e);this.renderCtx.lower2d.strokeStyle=t,this.renderCtx.lower2d.fillStyle=t,this.renderCtx.lower2d.font=this.state.font}}class ci extends we{render(e){const{lower2d:t}=this.renderCtx,{plot:s,position:o}=e,{width:i,height:a}=r.box.dims(s),l=this.tickFactory.create({...e,size:i});t.beginPath(),this.setColor(this.state.color),this.drawLine(o,r.xy.translate(o,"x",i));const u=this.drawTicks(l,(c,d)=>{this.drawLine(r.xy.translateX(o,d.position),r.xy.translate(o,{x:d.position,y:G})),t.fillText(d.label,o.x+d.position-c.width/2,o.y+G+c.height+rt,void 0,yt)});return t.stroke(),this.maybeDrawGrid(i,l,c=>[r.xy.translate(o,"x",c.position),r.xy.translate(o,{x:c.position,y:-a})]),{size:u.height+G+rt}}}class ui extends we{render(e){const{lower2d:t}=this.renderCtx,{plot:s}=e,{width:o,height:i}=r.box.dims(s),a=r.xy.translate(e.position,"y",e.size),l=this.tickFactory.create({...e,size:o});t.beginPath(),this.setColor(this.state.color),this.drawLine(a,r.xy.translate(a,"x",o));const u=this.drawTicks(l,(c,d)=>{this.drawLine(r.xy.translateX(a,d.position),r.xy.translate(a,{x:d.position,y:-G})),t.fillText(d.label,a.x+d.position-c.width/2,a.y-G-c.height-rt,void 0,yt)});return t.stroke(),this.maybeDrawGrid(o,l,c=>[r.xy.translate(a,"x",c.position),r.xy.translate(a,{x:c.position,y:i})]),{size:u.height+G}}}class $u extends we{render(e){const{lower2d:t}=this.renderCtx,{plot:s,position:o}=e,{height:i,width:a}=r.box.dims(s),l=r.xy.translate(o,"x",e.size),u=this.tickFactory.create({...e,size:i});t.beginPath(),this.setColor(this.state.color),this.drawLine(l,r.xy.translate(l,"y",i));const c=this.drawTicks(u,(d,f)=>{this.drawLine(r.xy.translateY(l,f.position),r.xy.translate(l,{x:-G,y:f.position})),t.fillText(f.label,l.x-d.width-G*2,l.y+f.position+d.height/2,void 0,yt)});return t.stroke(),this.maybeDrawGrid(i,u,d=>[r.xy.translate(l,"y",d.position),r.xy.translate(l,{x:a,y:d.position})]),{size:c.width+G*2}}}class hi extends we{render(e){const{lower2d:t}=this.renderCtx,{plot:s,position:o}=e,{height:i,width:a}=r.box.dims(s),l=this.tickFactory.create({...e,size:i});t.beginPath(),this.setColor(this.state.color),this.drawLine(o,r.xy.translateY(o,i));const u=this.drawTicks(l,(c,d)=>{this.drawLine(r.xy.translateY(o,d.position),r.xy.translate(o,{x:G,y:d.position})),t.fillText(d.label,o.x+G+rt,o.y+d.position+c.height/2,void 0,yt)});return t.stroke(),this.maybeDrawGrid(i,l,c=>[r.xy.translateY(o,c.position),r.xy.translate(o,{x:-a,y:c.position})]),{size:u.width+G+rt}}}const di=h.z.object({key:h.z.string(),size:h.z.number(),order:h.z.number(),loc:r.location.outer});h.z.record(h.z.string(),di);const me=(n,e)=>Object.values(e).filter(({loc:t})=>t===n).sort((t,s)=>s.order-t.order),Hu=(n,e,t)=>{const s=e[n];if(s==null)return r.xy.ZERO;const o=r.location.construct(s.loc),i=me(o,e),a=r.location.construct(r.direction.swap(r.location.direction(o))),l=me(a,e),u=i.findIndex(({key:f})=>f===n),c=i.slice(0,u).reduce((f,{size:p})=>f+p,0),d=l.reduce((f,{size:p})=>f+p,0);switch(o){case"left":return r.xy.translate(r.box.topLeft(t),[c,d]);case"right":return r.xy.translate(r.box.topRight(t),[c-s.size,d]);case"top":return r.xy.translate(r.box.topLeft(t),[d,c]);default:return r.xy.translate(r.box.bottomLeft(t),[d,-c-s.size])}},qu=(n,e)=>{const t=me("left",n),s=me("right",n),o=me("top",n),i=me("bottom",n),a=t.reduce((d,{size:f})=>d+f,0),l=s.reduce((d,{size:f})=>d+f,0),u=o.reduce((d,{size:f})=>d+f,0),c=i.reduce((d,{size:f})=>d+f,0);return r.box.construct(r.xy.translate(r.box.topLeft(e),{x:a,y:u}),r.box.width(e)-a-l,r.box.height(e)-u-c)},xt=Qs.extend({axisKey:h.z.string().optional(),bounds:r.bounds.bounds.optional(),autoBounds:h.z.object({lower:h.z.boolean().default(!0),upper:h.z.boolean().default(!0)}).or(h.z.boolean().default(!0)),autoBoundPadding:h.z.number().optional(),autoBoundUpdateInterval:r.TimeSpan.z.default(r.TimeSpan.seconds(10)),size:h.z.number().default(0),label:h.z.string().default(""),labelSize:h.z.number().default(0)}).partial({color:!0,font:!0,gridColor:!0}),ju=2,Wu=7,fi=(n,e)=>r.bounds.contains({lower:n-Wu,upper:n+ju},e),Vu=r.bounds.DECIMAL,Ar=r.TimeStamp.now(),Xu={lower:Number(Ar.valueOf()),upper:Number(Ar.add(r.TimeSpan.HOUR).valueOf())},pi=n=>n==="linear"?Vu:Xu,Gu=(n,e=.1,t)=>{const s=r.bounds.max(n.filter(r.bounds.isFinite));if(!r.bounds.isFinite(s))return pi(t);const{lower:o,upper:i}=s;if(i===o)return{lower:o-1,upper:i+1};const a=(i-o)*e;return{lower:o-a,upper:i+a}},Ku=.01,Qu=.1;class mi extends w.Composite{afterUpdate(e){const{internal:t}=this,{location:s,autoBoundUpdateInterval:o}=this.state;t.render=I.Context.use(e);const i=w.use(e),a=r.direction.construct(s);this.state.autoBoundPadding??=a==="x"?Qu:Ku,t.base=li(s,t.render,{color:i.colors.gray.l10,font:Je.fontString(i,{level:"small",code:!0}),gridColor:i.colors.gray.l1,...this.state}),ie(e,"layout"),t.updateBounds??=r.throttle(l=>this.setState(u=>({...u,bounds:l})),o.milliseconds)}afterDelete(e){ie(e,"layout")}renderAxis(e,t){if(!e.canvases.includes("lower2d"))return;const{base:s}=this.internal,{grid:o,container:i}=e,a=Hu(`${this.type}-${this.key}`,o,i),l={...e,position:a,decimalToDataScale:t,size:this.state.size+this.state.labelSize},{size:u}=s.render(l);fi(this.state.size,u)||this.setState(c=>({...c,size:u}))}iBounds(e,t){if(e&&this.internal.boundSnapshot!=null)return[this.internal.boundSnapshot,null];const{lower:s,upper:o}=gi(this.state.autoBounds);if(!s&&!o&&this.state.bounds!=null)return this.internal.boundSnapshot=this.state.bounds,[this.state.bounds,null];const i=c=>({upper:o||this.state.bounds==null?c.upper:this.state.bounds.upper,lower:s||this.state.bounds==null?c.lower:this.state.bounds.lower});let a,l=null;try{const c=t();a=Gu(c,this.state.autoBoundPadding,this.state.type)}catch(c){a=pi(this.state.type),l=c}const u=i(a);return this.internal.boundSnapshot=u,(this.state.bounds==null||s&&this.state.bounds.lower!==u.lower||o&&this.state.bounds.upper!==u.upper)&&this.internal.updateBounds?.(u),[u,l]}dataToDecimalScale(e,t,s){const[o,i]=this.iBounds(e,t),a=r.direction.swap(r.direction.construct(this.state.location));return[r.scale.Scale.scale(o).scale(1).translate(-r.box.root(s)[a]).magnify(1/r.box.dim(s,a)),i]}}const gi=n=>typeof n=="boolean"?{lower:n,upper:n}:{lower:n?.lower??!0,upper:n?.upper??!0};class Ee{canvas;theme;constructor(e,t){this.canvas=e,this.theme=t}rule({direction:e,region:t,position:s,...o}){return e==="x"?this.line({start:r.xy.construct(r.box.left(t),s),end:r.xy.construct(r.box.right(t),s),...o}):this.line({start:r.xy.construct(s,r.box.top(t)),end:r.xy.construct(s,r.box.bottom(t)),...o})}line({stroke:e,lineWidth:t,lineDash:s,start:o,end:i}){const a=this.canvas;a.strokeStyle=r.color.hex(e),a.lineWidth=t,a.setLineDash([s]),a.beginPath(),a.moveTo(...r.xy.couple(o)),a.lineTo(...r.xy.couple(i)),a.stroke()}circle({fill:e,stroke:t,strokeWidth:s,lineDash:o,radius:i,position:a,angle:l,lineCap:u}){const c=this.canvas;c.beginPath();const d=l?.lower??0,f=l?.upper??2*Math.PI;if(t!=null&&typeof i=="object"){const{inner:p,outer:g}=i,T=(p+g)/2,y=g-p;c.arc(...r.xy.couple(a),T,d,f,!1),c.strokeStyle=r.color.hex(t),c.lineWidth=s??y,u&&(c.lineCap=u),o!=null&&c.setLineDash([o]),c.stroke(),o!=null&&c.setLineDash([])}else if(t!=null&&typeof i=="number")c.arc(...r.xy.couple(a),i,d,f,!1),c.strokeStyle=r.color.hex(t),c.lineWidth=s??1,u&&(c.lineCap=u),o!=null&&c.setLineDash([o]),c.stroke(),o!=null&&c.setLineDash([]);else if(e!=null)if(c.fillStyle=r.color.hex(e),typeof i=="number")c.arc(...r.xy.couple(a),i,d,f),c.fill();else{const{inner:p,outer:g}=i;c.arc(...r.xy.couple(a),g,d,f,!1);const T=a.x+p*Math.cos(f),y=a.y+p*Math.sin(f);c.lineTo(T,y),c.arc(...r.xy.couple(a),p,f,d,!0),c.closePath(),c.fill()}}resolveColor(e,t){return e==null?t==null?this.theme.colors.text:this.resolveColor(t):typeof e=="function"?e(this.theme):r.color.construct(e)}border({region:e,color:t,width:s,radius:o,location:i}){const a=this.canvas;a.strokeStyle=r.color.hex(this.resolveColor(t,this.theme.colors.border)),a.lineWidth=s??this.theme.sizes.border.width,o??=this.theme.sizes.border.radius,i==null||i===!0?o>0?(a.roundRect(...r.xy.couple(r.box.topLeft(e)),...r.xy.couple(r.box.dims(e)),o),a.stroke()):(a.rect(...r.xy.couple(r.box.topLeft(e)),...r.xy.couple(r.box.dims(e))),a.stroke()):r.array.toArray(i).forEach(l=>{const[u,c]=r.box.edgePoints(e,l);a.beginPath(),a.moveTo(...r.xy.couple(u)),a.lineTo(...r.xy.couple(c)),a.stroke()})}container({region:e,bordered:t=!0,rounded:s=!0,borderColor:o,borderRadius:i,borderWidth:a,backgroundColor:l}){i??=this.theme.sizes.border.radius,a??=1;const u=this.canvas;u.fillStyle=r.color.hex(this.resolveColor(l,this.theme.colors.gray.l1)),u.strokeStyle=r.color.hex(this.resolveColor(o,this.theme.colors.border)),u.setLineDash([]),u.lineWidth=1,u.beginPath(),s?u.roundRect(...r.xy.couple(r.box.topLeft(e)),...r.xy.couple(r.box.dims(e)),i):u.rect(...r.xy.couple(r.box.topLeft(e)),...r.xy.couple(r.box.dims(e))),u.fill(),t&&this.border({region:e,color:o,radius:i,width:a,location:t})}textContainer(e){const[t,s]=this.spacedTextDrawF(e);t.width+=12,t.height+=12;const{root:o=r.location.TOP_LEFT,offset:i=r.xy.ZERO}=e,a={...e.position};o.x==="right"?a.x-=t.width+i.x:a.x+=i.x,o.y==="bottom"?a.y-=t.height+i.y:a.y+=i.y,this.container({region:r.box.construct(a,t.width,t.height),...e}),this.canvas.filter="none",s(r.xy.translate(a,[6,6]))}spacedTextDrawF({text:e,direction:t,spacing:s=1,level:o="p"}){const i=Je.fontString(this.theme,{level:o}),a=e.map(c=>sr.dimensions(c,i,this.canvas)),l=this.theme.sizes.base*s,u=Math.max(...a.map(c=>c[r.direction.dimension(t)]))+l;return[{[r.direction.dimension(r.direction.swap(t))]:Math.max(...a.map(c=>c[r.direction.dimension(r.direction.swap(t))])),[r.direction.dimension(t)]:u*e.length-l},c=>{const d=Je.fontString(this.theme,{level:o});this.canvas.font=d,this.canvas.fillStyle=r.color.hex(this.theme.colors.text),this.canvas.textBaseline="top",this.canvas.textAlign="start",e.forEach((f,p)=>{this.canvas.fillText(f,c.x,c.y+u*p)})}]}list({length:e,itemHeight:t,width:s,spacing:o=0,position:i,draw:a,root:l=r.location.TOP_LEFT,offset:u=r.xy.ZERO,padding:c=r.xy.ZERO}){const d=e*t+c.y*2+o*(e-1),f=s+c.x*2,p={...i};l.x==="right"?p.x-=s+u.x*2:p.x+=u.x,l.y==="top"?p.y-=d+u.y*2:p.y+=u.y,this.container({region:r.box.construct(p,{width:f,height:d}),backgroundColor:g=>g.colors.gray.l1});for(let g=0;g<e;g++){const T=r.box.construct(r.xy.construct(p.x+c.x,p.y+g*t+c.y+o*g),s,t);a(g,T)}}drawTextInCenter({box:e,text:t,level:s}){const o=sr.dimensions(t,this.canvas.font,this.canvas),i=r.box.positionInCenter(r.box.construct(r.xy.ZERO,o),e);return this.text({text:t,position:r.box.topLeft(i),level:s})}text({text:e,position:t,level:s="p",weight:o,shade:i,maxWidth:a,code:l,justify:u="left",align:c="top",useAtlas:d,color:f}){this.canvas.font=Je.fontString(this.theme,{level:s,weight:o,code:l}),f!=null?this.canvas.fillStyle=r.color.hex(this.resolveColor(f)):i==null?this.canvas.fillStyle=r.color.hex(this.theme.colors.text):this.canvas.fillStyle=r.color.hex(this.theme.colors.gray[`l${i}`]),this.canvas.textAlign=u,this.canvas.textBaseline=c;let p;a!=null&&(p=this.canvas.scissor(r.box.construct(t,a,1e3))),this.canvas.fillText(e,t.x,t.y,void 0,{useAtlas:d}),p?.()}}const Js=h.z.object({position:h.z.number().optional(),pixelPosition:h.z.number().optional(),dragging:h.z.boolean(),lineWidth:h.z.number().default(1),lineDash:h.z.number().default(20),color:r.color.colorZ}),Ju=3;class ot extends w.Leaf{static TYPE="Rule";schema=Js;lastUpdateRef=null;afterUpdate(e){this.internal.renderCtx=I.Context.use(e);const t=w.use(e);this.internal.draw=new Ee(this.internal.renderCtx.upper2d,t),ie(e,"tool")}afterDelete(e){ie(e,"tool")}updatePositions({decimalToDataScale:e,plot:t}){const s=this.state.dragging,o=this.prevState.dragging&&!s;if((s||o)&&this.state.pixelPosition!=null){if(this.lastUpdateRef??=this.state.pixelPosition,Math.abs(this.state.pixelPosition-this.lastUpdateRef)<Ju&&!o)return this.state.pixelPosition;this.lastUpdateRef=this.state.pixelPosition;const l=e.pos(this.state.pixelPosition/r.box.height(t));return this.setState(u=>({...u,position:l})),this.state.pixelPosition}if(this.state.position==null){const a=e.pos(.5);this.setState(l=>({...l,position:a}))}const i=e.reverse().pos(this.state.position)*r.box.height(t);if(!isNaN(i)){if(this.state.pixelPosition!=null&&Math.abs(i-this.state.pixelPosition)<1)return this.state.pixelPosition;this.setState(a=>({...a,pixelPosition:i}))}return i}render(e){if(this.deleted)return;const{renderCtx:t}=this.internal,{location:s,plot:o}=e,i=r.location.direction(s),{upper2d:a}=t,l=this.internal.draw,u=this.updatePositions(e)+r.box.top(e.plot);l.rule({stroke:this.state.color,lineWidth:this.state.lineWidth,lineDash:this.state.lineDash,direction:i,region:o,position:u}),a.fillStyle=r.color.hex(this.state.color),a.lineJoin="round",a.lineWidth=3.5,a.lineCap="round",a.beginPath();const c=4;if(s==="left"){const d=r.box.left(o)-1;a.moveTo(d,u),a.lineTo(d-c,u-c),a.lineTo(d-c,u+c)}else s==="right"&&(a.moveTo(r.box.right(o),u),a.lineTo(r.box.right(o)+c,u-c),a.lineTo(r.box.right(o)+c,u+c));a.closePath(),a.stroke()}}const yi={[ot.TYPE]:ot},eh=Object.freeze(Object.defineProperty({__proto__:null,REGISTRY:yi,Rule:ot,ruleStateZ:Js},Symbol.toStringTag,{value:"Module"})),th=xt.extend({location:r.location.x.default("left")}),Ir=2,nh=n=>r.box.signedWidth(n)<Ir||r.box.signedHeight(n)<Ir;class Qt extends mi{static TYPE="YAxis";schema=xt;xBounds(){return r.bounds.max(this.lines.map(e=>e.xBounds()).filter(e=>r.bounds.isFinite(e)))}bounds(e){const[t,s]=this.iBounds(e,this.dataBounds.bind(this));if(s!=null)throw s;return t}render(e){if(this.deleted)return;const[t,s]=this.dataToDecimalScale(e.hold,this.dataBounds.bind(this),e.viewport),o=t.invert().reverse();if(this.renderAxis(e,o),this.renderLines(e,t),this.renderRules(e,o),s!=null)throw s}renderLines({xDataToDecimalScale:e,plot:t,canvases:s,exposure:o},i){if(!s.includes("gl")||nh(t))return;const a={region:t,dataToDecimalScale:new r.scale.XY(e,i),exposure:o};this.lines.forEach(l=>l.render(a))}renderRules({container:e,plot:t,canvases:s},o){if(!s.includes("upper2d"))return;const{location:i}=this.state,{render:a}=this.internal,l=r.box.construct(r.box.left(e),r.box.top(t),r.box.width(e),r.box.height(t)),u=a.scissor(l,r.xy.ZERO,["upper2d"]),c={container:e,plot:t,decimalToDataScale:o,location:i};this.rules.map(d=>d.render(c)),u()}findByXValue({xDataToDecimalScale:e,plot:t,viewport:s,hold:o,exposure:i},a){const[l,u]=this.dataToDecimalScale(o,this.dataBounds.bind(this),s);if(u!=null)throw u;const c=new r.scale.XY(e,l),d={region:t,dataToDecimalScale:c,exposure:i};return this.lines.map(f=>({...f.findByXValue(d,a),units:this.state.label}))}dataBounds(){return this.lines.map(e=>e.yBounds())}get lines(){return this.childrenOfType($t.TYPE)}get rules(){return this.childrenOfType(ot.TYPE)}}const sh=h.z.object({start:r.TimeStamp.z,end:r.TimeStamp.z});class zr extends w.Leaf{static TYPE="range-annotation";schema=sh;afterUpdate(e){this.internal.render=I.Context.use(e),this.internal.draw=new Ee(this.internal.render.upper2d,w.use(e))}}const rh=x.ranger.payloadZ.extend({viewport:r.bounds.bounds}),xi=h.z.object({cursor:r.xy.xy.or(h.z.null()),hovered:rh.or(h.z.null()),count:h.z.number()});class Jt extends w.Leaf{static TYPE="range-provider";schema=xi;fetchedInitial=r.TimeRange.ZERO;afterUpdate(e){const{internal:t}=this;t.render=I.Context.use(e),t.draw=new Ee(t.render.upper2d,w.use(e)),t.requestRender=an(e),t.runAsync=w.useErrorHandler(e),t.ranges??=new Map;const s=He(e);if(t.requestRender("tool"),s==null)return;t.client=s;const o=Ki(e,this.key);t.removeListener?.();const i=o.ranges.onSet(l=>{t.client!=null&&(r.color.isCrude(l.color)&&t.ranges.set(l.key,t.client.ranges.sugarOne(l)),this.setState(u=>({...u,count:t.ranges.size})),t.requestRender("tool"))}),a=o.ranges.onDelete(async l=>{t.ranges.delete(l),this.setState(u=>({...u,count:t.ranges.size})),t.requestRender("tool")});t.removeListener=()=>{i(),a()}}fetchInitial(e){const{internal:t}=this,{client:s,runAsync:o}=t;s==null||this.fetchedInitial.equals(e,r.TimeSpan.minutes(1))||(this.fetchedInitial=e,o(async()=>{(await s.ranges.retrieve(e)).forEach(a=>{r.color.isCrude(a.color)&&t.ranges.set(a.key,a)}),this.setState(a=>({...a,count:t.ranges.size}))},"failed to fetch initial ranges"))}render(e){const{dataToDecimalScale:t,region:s,viewport:o,timeRange:i}=e;this.fetchInitial(i);const{draw:a,ranges:l}=this.internal,u=t.scale(r.box.xBounds(s)),c=this.state.cursor==null?null:this.state.cursor.x;let d=null;const f=a.canvas.scissor(r.box.construct({x:r.box.left(s),y:r.box.top(s)-35},{x:r.box.right(s),y:r.box.bottom(s)}));l.forEach(p=>{const g=r.color.colorZ.safeParse(p.color);if(!g.success)return;const T=g.data;let y=u.pos(Number(p.timeRange.start.valueOf()));const v=u.pos(Number(p.timeRange.end.valueOf()));if(v<r.box.left(s)||y>r.box.right(s))return;y=r.clamp(y,r.box.left(s)-2,r.box.right(s)-1);let R=!1;c!=null&&(R=r.bounds.contains({lower:y,upper:v},c)),R&&(d={key:p.key,parent:p.parent,name:p.name,color:p.color,labels:p.labels,timeRange:p.timeRange,viewport:{lower:t.scale(r.box.xBounds(o)).pos(Number(p.timeRange.start.valueOf())),upper:t.scale(r.box.xBounds(o)).pos(Number(p.timeRange.end.valueOf()))}}),a.container({region:r.box.construct({x:y,y:r.box.top(s)-1},{x:v,y:r.box.bottom(s)-1}),backgroundColor:r.color.setAlpha(T,.2),bordered:!1});const L=r.box.construct({x:y+1,y:r.box.top(s)-34},{x:v-1,y:r.box.top(s)-12});a.container({region:L,backgroundColor:r.box.width(L)<20?r.color.setAlpha(T,.4):k=>R?k.colors.gray.l2:k.colors.gray.l0,bordered:!0,borderWidth:1,borderRadius:2,borderColor:r.color.setAlpha(T,.8)}),a.text({text:p.name,position:{x:y+8,y:r.box.top(s)-30},level:"small",shade:10,weight:500,maxWidth:v-y-16})}),f(),d!=null?this.setState(p=>({...p,hovered:d})):this.state.hovered&&this.setState(p=>({...p,hovered:null}))}}const oh={[zr.TYPE]:zr,[Jt.TYPE]:Jt},ih=xt;class en extends mi{static TYPE="XAxis";schema=xt;render(e){if(this.deleted)return;const[t,s]=this.dataToDecimalScale(e.hold,this.dataBounds.bind(this),e.viewport);if(this.renderAxis(e,t.reverse()),this.renderYAxes(e,t),this.renderRanges(e,t),s!=null)throw s}findByXDecimal(e,t){const[s,o]=this.dataToDecimalScale(e.hold,this.dataBounds.bind(this),e.viewport);if(o!=null)throw o;return this.findByXValue(e,s.reverse().pos(t))}findByXValue(e,t){const[s,o]=this.dataToDecimalScale(e.hold,this.dataBounds.bind(this),e.viewport);if(o!=null)throw o;const i={...e,xDataToDecimalScale:s};return this.yAxes.map(a=>a.findByXValue(i,t)).flat()}renderYAxes(e,t){const s={...e,xDataToDecimalScale:t};this.yAxes.forEach(o=>o.render(s))}get yAxes(){return this.childrenOfType(Qt.TYPE)}get ranges(){return this.childrenOfType(Jt.TYPE)}bounds(e){const[t,s]=this.iBounds(e,this.dataBounds.bind(this));if(s!=null)throw s;return t}renderRanges(e,t){const s=this.bounds(e.hold),o=r.bounds.min([s,r.TimeRange.MAX.numericBounds]),i=new r.TimeRange(o.lower,o.upper);this.ranges.forEach(a=>a.render({dataToDecimalScale:t,region:e.plot,viewport:e.viewport,timeRange:i}))}dataBounds(){return this.yAxes.map(e=>e.xBounds())}}const ah=r.xy.construct(12),lh=3,ch=14,uh=r.xy.construct(6),er=h.z.object({position:r.xy.xy.or(h.z.null()),textColor:r.color.colorZ.default(r.color.ZERO),backgroundColor:r.color.colorZ.default(r.color.ZERO),borderColor:r.color.colorZ.default(r.color.ZERO),ruleColor:r.color.colorZ.default(r.color.ZERO),ruleStrokeWidth:h.z.number().default(1),ruleStrokeDash:h.z.number().default(0)});class it extends w.Leaf{static TYPE="tooltip";schema=er;afterUpdate(e){const t=w.use(e);r.color.isZero(this.state.textColor)&&(this.state.textColor=t.colors.text),r.color.isZero(this.state.backgroundColor)&&(this.state.backgroundColor=t.colors.gray.l1),r.color.isZero(this.state.borderColor)&&(this.state.borderColor=t.colors.border),r.color.isZero(this.state.ruleColor)&&(this.state.ruleColor=t.colors.gray.l7),this.internal.dotColor=t.colors.text,this.internal.dotColorContrast=t.colors.textInverted,this.internal.render=I.Context.use(e),this.internal.draw=new Ee(this.internal.render.upper2d,t),ie(e,"tool")}afterDelete(e){ie(e,"tool")}render(e){if(this.deleted||this.state.position==null)return;const{region:t}=e,s=r.scale.XY.scale(r.box.DECIMAL).scale(t),o=r.scale.XY.scale(t).scale(r.box.DECIMAL),i=e.findByXDecimal(o.x.pos(this.state.position.x)),a=i.filter(y=>r.xy.isFinite(y.value)),{draw:l}=this.internal,u=a.reduce((y,v)=>y+v.position.x,0)/a.length,c=new r.TimeStamp(a.reduce((y,v)=>y+v.value.x,0)/a.length),d=s.x.pos(u);if(!r.bounds.contains(r.box.xBounds(t),d))return;l.rule({stroke:this.state.ruleColor,lineWidth:this.state.ruleStrokeWidth,lineDash:this.state.ruleStrokeDash,direction:"y",region:t,position:d}),a.forEach(y=>{const v=s.pos(y.position);l.circle({fill:r.color.setAlpha(y.color,.5),radius:8,position:v}),l.circle({fill:r.color.setAlpha(y.color,.8),radius:5,position:v}),l.circle({fill:r.color.pickByContrast(y.color,this.internal.dotColor,this.internal.dotColorContrast),radius:2,position:v})});const f=o.pos(this.state.position),p={...r.location.TOP_LEFT};f.x>.6&&(p.x="right"),f.y>.6&&(p.y="bottom");let g=i.reduce((y,v)=>Math.max(y,v.label?.length??0),0);const T=c.toString("preciseDate","local").length;T>g&&(g=T),l.list({root:p,offset:ah,length:a.length+1,padding:uh,itemHeight:ch,spacing:lh,width:g*7+48,position:this.state.position,draw:(y,v)=>{let R="",L="",k=this.state.textColor;if(y===0)R="Time",L=c.toString("preciseDate","local");else{const C=a[y-1];R=C.label??"",L=r.math.smartRound(C.value.y,C.bounds).toString(),k=C.color}l.text({position:r.box.topLeft(v),text:R,level:"small",weight:500,color:k}),l.text({position:r.xy.translateY(r.box.topRight(v),-1),text:L,level:"small",justify:"right",code:!0,shade:10})}})}}const bi={[it.TYPE]:it},hh=Object.freeze(Object.defineProperty({__proto__:null,REGISTRY:bi,Tooltip:it,tooltipStateZ:er},Symbol.toStringTag,{value:"Module"})),Si=h.z.enum(["one","two"]),tr=h.z.object({one:r.xy.xy.nullable(),two:r.xy.xy.nullable(),hover:r.xy.xy.nullable(),mode:Si.default("one"),color:h.z.union([r.color.colorZ,h.z.object({verticalLine:r.color.colorZ.default(r.color.ZERO),horizontalLine:r.color.colorZ.default(r.color.ZERO),obliqueLine:r.color.colorZ.default(r.color.ZERO)})]).optional().default(r.color.ZERO),strokeWidth:h.z.number().default(1),strokeDash:h.z.number().default(2)}),dh=n=>n==="one"?"1":"2",fh=n=>n.colors.error.z,ph=n=>n.colors.secondary.z,mh=n=>n.colors.gray.l9,Xe=6,Ge=14,Ke=8,Et=8,Ct=3,gh=9,yh=8,xh=2,bh=2,Sh=8,Th=5,vh=2,wh=.5,Eh=.8,Rt=50,Pt=80,Ch=30,Rh=30,Ph=10,Lh=40,kh=100,_h=30,Re=15,Yr=8,Oh=10;class at extends w.Leaf{static TYPE="measure";schema=tr;afterUpdate(e){const t=I.Context.use(e);this.internal.theme=w.use(e),this.internal.renderCtx=t,this.internal.draw=new Ee(t.upper2d,this.internal.theme),ie(e,"tool"),this.internal.dotColor=this.internal.theme.colors.text,this.internal.dotColorContrast=this.internal.theme.colors.textInverted}afterDelete(e){ie(e,"layout")}get verticalLineColor(){return r.color.isColor(this.state.color)?r.color.isZero(this.state.color)?this.internal.theme.colors.gray.l8:this.state.color:r.color.isZero(this.state.color.verticalLine)?this.internal.theme.colors.gray.l8:this.state.color.verticalLine}get horizontalLineColor(){return r.color.isColor(this.state.color)?r.color.isZero(this.state.color)?this.internal.theme.colors.gray.l8:this.state.color:r.color.isZero(this.state.color.horizontalLine)?this.internal.theme.colors.gray.l8:this.state.color.horizontalLine}get obliqueLineColor(){return r.color.isColor(this.state.color)?r.color.isZero(this.state.color)?this.internal.theme.colors.gray.l8:this.state.color:r.color.isZero(this.state.color.obliqueLine)?this.internal.theme.colors.gray.l8:this.state.color.obliqueLine}findPoint(e,t,s,o,i){const a=o!=null&&!r.xy.equals(t,o);if(s!=null&&!a){const c=e.findByXValue(s.x).filter(d=>Number.isFinite(d.value.x)&&Number.isFinite(d.value.y));return c.length>0?c.sort((d,f)=>r.xy.distance(s,d.value)-r.xy.distance(s,f.value))[0]:null}const l=i.pos(t),u=e.findByXDecimal(l.x).filter(c=>Number.isFinite(c.value.x)&&Number.isFinite(c.value.y));return u.length===0?null:u.sort((c,d)=>r.xy.distance(l,c.position)-r.xy.distance(l,d.position))[0]}find(e){const{one:t,two:s}=this.state;if(t==null||s==null)return null;const{dataOne:o,dataTwo:i,clickOne:a,clickTwo:l}=this.internal,u=r.scale.XY.scale(e.region).scale(r.box.DECIMAL),c=this.findPoint(e,t,o,a,u);if(c==null)return null;(a==null||!r.xy.equals(t,a))&&(this.internal.dataOne={...c.value},this.internal.clickOne={...t});const d=this.findPoint(e,s,i,l,u);return d==null?null:((l==null||!r.xy.equals(s,l))&&(this.internal.dataTwo={...d.value},this.internal.clickTwo={...s}),[c,d])}drawLabelValue(e,t,s,o){const{draw:i}=this.internal,a=r.xy.construct(Xe),l=e.length*Ke,u=t.length*Et,c=l+u+a.x*Ct,d=Ge+a.y*2,f=r.box.construct(s,c,d);i.container({region:f,backgroundColor:p=>p.colors.gray.l1}),i.text({text:e,position:r.xy.translate(r.box.topLeft(f),a),level:"small",weight:500,color:o(this.internal.theme)}),i.text({text:t,position:r.xy.translate(r.box.topRight(f),[-a.x-1,a.y-1]),level:"small",justify:"right",code:!0,shade:10})}drawCombinedDeltaLabel(e,t,s,o,i,a){const{draw:l,theme:u}=this.internal,c=r.xy.construct(Xe),d=Ke*5,f=Math.max(t.length,s.length,o.length),p=d+f*Et+c.x*Ct,g=Ge,T=g*3+c.y*2;let y;if(a){const v=r.xy.translate(e,[-p/2,-T/2]);y=r.box.construct(v,p,T)}else if(y=r.box.construct(e,p,T),r.box.right(y)>r.box.right(i)){const v=r.xy.translateX(e,-p-Pt*2);y=r.box.construct(v,p,T)}l.container({region:y,backgroundColor:v=>v.colors.gray.l1}),this.drawPointLabelRow({region:y,label:"ΔX",value:t,labelColor:u.colors.error.z,yOffset:0,leftOffset:0}),this.drawPointLabelRow({region:y,label:"ΔY",value:s,labelColor:u.colors.secondary.z,yOffset:g,leftOffset:0}),this.drawPointLabelRow({region:y,label:"Slope",value:o,labelColor:u.colors.gray.l9,yOffset:g*2,leftOffset:0})}drawPointLabelRow(e){const{region:t,label:s,value:o,labelColor:i,yOffset:a,leftOffset:l}=e,{draw:u}=this.internal,c=r.xy.construct(Xe);u.text({text:s,position:r.xy.translate(r.box.topLeft(t),[c.x+l,c.y+a]),level:"small",weight:500,color:i}),u.text({text:o,position:r.xy.translate(r.box.topRight(t),[-c.x-1,c.y+a-1]),level:"small",justify:"right",code:!0,shade:10})}drawPointLabel(e){const{pointNumber:t,position:s,value:o,units:i,bounds:a,toTop:l,viewRegion:u,xDist:c}=e,{draw:d,theme:f}=this.internal,p=new r.TimeStamp(o.x),g=p.toString(p.formatBySpan(c),"local"),T=`${r.math.smartRound(o.y,a)} ${i??""}`,y=`${t}`,v=y.length*Ke,R=r.xy.construct(Xe),L=Ke,k=Math.max(g.length,T.length),C=v+Yr+L+k*Et+R.x*Ct,Z=Ge,b=Z*2+R.y*2;let M=l?-(b+Re):Re,A=r.box.construct(r.xy.translate(s,[-C/2,M]),C,b);(l&&r.box.top(A)<r.box.top(u)||!l&&r.box.bottom(A)>r.box.bottom(u))&&(M=l?Re:-(b+Re),A=r.box.construct(r.xy.translate(s,[-C/2,M]),C,b)),d.container({region:A,backgroundColor:K=>K.colors.gray.l1}),d.text({text:y,position:r.xy.translate(r.box.topLeft(A),[R.x,R.y]),level:"small",weight:500,color:f.colors.gray.l9});const V=v+Yr;this.drawPointLabelRow({region:A,label:"X",value:g,labelColor:f.colors.error.z,yOffset:0,leftOffset:V}),this.drawPointLabelRow({region:A,label:"Y",value:T,labelColor:f.colors.secondary.z,yOffset:Z,leftOffset:V})}drawPointMarker(e,t){const{draw:s}=this.internal;s.circle({fill:r.color.setAlpha(t,wh),radius:Sh,position:e}),s.circle({fill:r.color.setAlpha(t,Eh),radius:Th,position:e}),s.circle({fill:r.color.pickByContrast(t,this.internal.dotColor,this.internal.dotColorContrast),radius:vh,position:e})}calculateYLabelPosition(e,t,s){return t?r.xy.translateX(e,Ch):s?r.xy.translateX(e,Rh):e}calculateXLabelPosition(e,t,s){return t?r.xy.translateY(e,Lh):s?r.xy.translateY(e,Ph):e}calculateSlopeLabelPosition(e){const{basePos:t,yLabelPos:s,isVeryClose:o,isHorizontal:i,xPixelDist:a,yPixelDist:l}=e;return o?r.xy.translateX(t,Pt):i?r.xy.translateY(t,-35):Math.abs(t.x-s.x)<kh&&Math.abs(t.y-s.y)<_h?a<l?r.xy.translateY(t,-35):r.xy.translateX(t,Pt):t}renderHover(e){if(this.state.hover==null)return;const t=this.state.hover,s=r.scale.XY.scale(e.region).scale(r.box.DECIMAL),o=s.pos(t),i=e.findByXDecimal(s.pos(t).x);if(i.length===0)return;const a=i.sort((c,d)=>r.xy.distance(o,c.position)-r.xy.distance(o,d.position))[0],{draw:l}=this.internal,u=s.reverse().pos(a.position);l.circle({stroke:r.color.setAlpha(a.color,1),strokeWidth:xh,lineDash:bh,radius:gh,position:u}),l.circle({fill:this.internal.theme.colors.gray.l3,radius:yh,position:u}),l.text({text:dh(this.state.mode),position:u,level:"small",align:"middle",justify:"center"})}render(e){if(this.deleted)return;this.renderHover(e);const t=this.find(e);if(t==null)return;const[s,o]=t,{draw:i}=this.internal,{strokeDash:a,strokeWidth:l}=this.state,u=r.scale.XY.scale(r.box.DECIMAL).scale(e.region),c=u.pos(s.position),d=u.pos(o.position),f=Math.abs(s.value.x-o.value.x),p=o.value.y-s.value.y,g=Math.abs(p);if(!Number.isFinite(f)||!Number.isFinite(g))return;const T=new r.TimeSpan(f),y=p/T.seconds,v=Math.abs(c.x-d.x),R=Math.abs(c.y-d.y),L=R<Rt,k=v<Rt,C=v<Rt||R<Rt;i.line({start:r.xy.construct(c.x,c.y),end:r.xy.construct(c.x,d.y),stroke:this.verticalLineColor,lineDash:a,lineWidth:l}),i.line({start:r.xy.construct(c.x,d.y),end:r.xy.construct(d.x,d.y),stroke:this.horizontalLineColor,lineDash:a,lineWidth:l}),i.line({start:r.xy.construct(c.x,c.y),end:r.xy.construct(d.x,d.y),stroke:this.obliqueLineColor,lineDash:a,lineWidth:l}),this.drawPointMarker(c,s.color),this.drawPointMarker(d,o.color);const Z=`${r.math.smartRound(g,r.bounds.construct(g))} ${s.units??""}`,b=T.lessThan(r.TimeSpan.milliseconds(Oh))?r.TimeSpan.MICROSECOND:r.TimeSpan.MILLISECOND,M=T.truncate(b).toString();let A=r.math.smartRound(y,r.bounds.construct(Math.abs(y))).toString();if(s.units!=null&&s.units.length>0&&(A+=` ${s.units} / s`),C){const K=r.xy.construct((c.x+d.x)/2,(c.y+d.y)/2),ue=Ke*6,E=Math.max(M.length,Z.length,A.length),$=Xe,N=ue+E*Et+$*Ct,Q=Ge*3+$*2,de=r.box.construct(r.xy.translate(K,[-N/2,-Q/2]),N,Q),ne=c.y<d.y,J=150,se=Ge*2+$*2,H=ne?-55:Re,xn=r.box.construct(r.xy.translate(c,[-J/2,H]),J,se),bn=ne?Re:-55,Sn=r.box.construct(r.xy.translate(d,[-J/2,bn]),J,se),Tn=r.box.area(r.box.intersection(de,xn))>0,vn=r.box.area(r.box.intersection(de,Sn))>0,bt=!Tn&&!vn,wn=bt?K:r.xy.construct(Math.max(c.x,d.x)+Pt,(c.y+d.y)/2);this.drawCombinedDeltaLabel(wn,M,Z,A,e.region,bt)}else{const K=this.calculateYLabelPosition(r.xy.construct(c.x,(c.y+d.y)/2),C,k);this.drawLabelValue("ΔY",Z,K,ph);const ue=this.calculateXLabelPosition(r.xy.construct((c.x+d.x)/2,d.y),C,L);this.drawLabelValue("ΔX",M,r.xy.translateX(ue,-15),fh);const E=this.calculateSlopeLabelPosition({basePos:r.xy.construct((c.x+d.x)/2,(c.y+d.y)/2),yLabelPos:K,isVeryClose:C,isHorizontal:L,xPixelDist:v,yPixelDist:R});this.drawLabelValue("Slope",A,E,mh)}const V=c.y<d.y;this.drawPointLabel({pointNumber:1,position:c,value:s.value,units:s.units??null,bounds:s.bounds,toTop:V,viewRegion:e.region,xDist:T}),this.drawPointLabel({pointNumber:2,position:d,value:o.value,units:o.units??null,bounds:o.bounds,toTop:!V,viewRegion:e.region,xDist:T})}}const Ti={[at.TYPE]:at},Mh=Object.freeze(Object.defineProperty({__proto__:null,Measure:at,REGISTRY:Ti,measureStateZ:tr,modeZ:Si},Symbol.toStringTag,{value:"Module"})),vi=h.z.object({container:r.box.box,viewport:r.box.box,hold:h.z.boolean().default(!1),grid:h.z.record(h.z.string(),di),visible:h.z.boolean().default(!0),clearOverScan:r.xy.crudeZ.default(r.xy.ZERO)}),Dh=h.z.record(h.z.string(),h.z.object({lower:h.z.number(),upper:h.z.number()})),wi={getBounds:h.z.function({input:h.z.tuple([]),output:Dh})},Ah=(n,e)=>{const t=r.box.width(n)*Math.sqrt(r.box.height(n)),s=r.box.width(e)*Math.sqrt(r.box.height(e));return t/s},Ih=["upper2d","lower2d","gl"],zh=["upper2d"];class Jn extends w.Composite{static TYPE="LinePlot";schema=vi;methods=wi;afterUpdate(e){this.internal.instrumentation=I.useInstrumentation(e,"lineplot"),this.internal.handleError=w.useErrorHandler(e),this.internal.renderCtx=I.Context.use(e),on(e,t=>{this.state.visible&&this.requestRender("low",t)}),!(!this.state.visible&&!this.prevState.visible)&&this.requestRender("high","layout")}afterDelete(e){this.internal.renderCtx=I.Context.use(e),this.requestRender("high","layout")}findByXDecimal(e){const t={...this.state,plot:this.calculatePlot(),exposure:this.exposure};return this.axes.flatMap(s=>s.findByXDecimal(t,e)).flat()}findByXValue(e){const t={...this.state,plot:this.calculatePlot(),exposure:this.exposure};return this.axes.flatMap(s=>s.findByXValue(t,e)).flat()}get axes(){return this.childrenOfType(en.TYPE)}get tooltips(){return this.childrenOfType(it.TYPE)}get measures(){return this.childrenOfType(at.TYPE)}get exposure(){return Ah(this.state.viewport,this.state.container)}renderAxes(e,t){const s={...this.state,plot:e,canvases:t,exposure:this.exposure};this.axes.forEach(o=>o.render(s))}renderTooltips(e,t){const s={findByXDecimal:this.findByXDecimal.bind(this),region:e,canvases:t};this.tooltips.forEach(o=>o.render(s))}getBounds(){const e={};return this.axes.forEach(t=>{const s=t.state.axisKey??t.key;e[s]=t.bounds(this.state.hold),t.yAxes.forEach(o=>{const i=o.state.axisKey??o.key;e[i]=o.bounds(this.state.hold)})}),e}renderMeasures(e){const t={findByXDecimal:this.findByXDecimal.bind(this),findByXValue:this.findByXValue.bind(this),region:e};this.measures.forEach(s=>s.render(t))}calculatePlot(){return qu(this.state.grid,this.state.container)}render(e){const{instrumentation:t,renderCtx:s,handleError:o}=this.internal;if(this.deleted){t.L.debug("deleted, skipping render",{key:this.key});return}if(!this.state.visible)return t.L.debug("not visible, skipping render",{key:this.key}),({canvases:d})=>s.erase(this.state.container,this.state.clearOverScan,...d);const i=this.calculatePlot();t.L.debug("rendering",{key:this.key,viewport:this.state.viewport,container:this.state.container,grid:this.state.grid,plot:i,canvases:e});const a=r.xy.construct(this.state.clearOverScan),l=s.scissor(this.state.container,a,e.filter(d=>d!=="gl")),u=s.scissor(i,r.xy.ZERO,e.filter(d=>d==="gl"));try{this.renderAxes(i,e),this.renderTooltips(i,e),this.renderMeasures(i)}catch(d){o(d,"failed to render line plot")}finally{l(),u()}t.L.debug("rendered",{key:this.key});const c=r.box.copy(this.state.container);return({canvases:d})=>s.erase(c,this.state.clearOverScan,...d)}requestRender(e,t){const{renderCtx:s}=this.internal;let o=Ih;t==="tool"&&(o=zh),s.loop.set({key:`${this.type}-${this.key}`,render:()=>this.render(o),priority:e,canvases:o})}}const Yh={[Jn.TYPE]:Jn,[en.TYPE]:en,[Qt.TYPE]:Qt},Ei=h.z.object({region:r.box.box,wheelPos:h.z.number(),scrolling:h.z.boolean(),empty:h.z.boolean(),visible:h.z.boolean(),telem:Mt.default(eo),font:ge.levelZ.default("p"),color:r.color.colorZ.default(r.color.ZERO),overshoot:r.xy.xy.default({x:0,y:0})}),Nh=.98,Qe="lower2d",Zh={offset:0n,offsetRef:0n,scrollRef:0};class lt extends w.Leaf{static TYPE="log";static z=Ei;schema=lt.z;values=new r.MultiSeries([]);scrollState=Zh;afterUpdate(e){const{internal:t}=this;t.render=I.Context.use(e),t.theme=w.use(e),r.color.isZero(this.state.color)?this.internal.textColor=t.theme.colors.gray.l11:t.textColor=this.state.color,t.telem=U(e,this.state.telem,t.telem);const{scrolling:s,wheelPos:o}=this.state;if(this.state.scrolling&&!this.prevState.scrolling){const u=this.values.alignmentBounds.upper-1n;this.scrollState={offset:u,offsetRef:u,scrollRef:this.state.wheelPos}}else if(s){const{scrollState:u,values:c}=this,d=Math.ceil((o-this.scrollState.scrollRef)/this.lineHeight);u.offset=this.values.traverseAlignment(u.offsetRef,-BigInt(d)),u.offset<c.alignmentBounds.lower+BigInt(this.visibleLineCount)&&(u.offset=c.alignmentBounds.lower,this.setState(f=>({...f,wheelPos:this.prevState.wheelPos}))),u.offset>=c.alignmentBounds.upper&&this.setState(f=>({...f,scrolling:!1}))}const[a,l]=this.internal.telem.value();this.values=l,this.checkEmpty(),t.stopListeningTelem?.(),t.stopListeningTelem=t.telem.onChange(()=>{const[u,c]=this.internal.telem.value();this.checkEmpty(),this.values=c,this.requestRender()}),!(!this.state.visible&&!this.prevState.visible)&&this.requestRender()}checkEmpty(){const e=this.values.length===0;e!==this.state.empty&&this.setState(t=>({...t,empty:e}))}afterDelete(){const{telem:e,render:t}=this.internal;e.cleanup?.(),t.erase(r.box.construct(this.state.region),r.xy.ZERO,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((r.box.height(this.state.region)-12)/this.lineHeight),this.values.length)}render(){const{render:e}=this.internal,t=this.state.region;if(r.box.areaIsZero(t))return;if(!this.state.visible)return()=>e.erase(t,r.xy.ZERO,Qe);let s;if(!this.state.scrolling)s=this.values.subIterator(this.values.length-this.visibleLineCount,this.values.length);else{const c=this.values.traverseAlignment(this.scrollState.offset,-BigInt(this.visibleLineCount));s=this.values.subAlignmentSpanIterator(c,this.visibleLineCount)}const o=this.state.region,i=e[Qe],a=new Ee(i,this.internal.theme),l=e.scissor(o,r.xy.ZERO,[Qe]);this.renderElements(a,s),this.renderScrollbar(a),l();const u=r.box.copy(this.state.region);return({canvases:c})=>e.erase(u,this.state.overshoot,...c)}renderScrollbar(e){const t=this.state.region,s=r.box.height(t)/this.totalHeight*r.box.height(t);if(s>=r.box.height(t)*Nh)return;let o=r.box.bottom(t)-s;this.state.scrolling&&(o-=Number(this.values.distance(this.values.alignmentBounds.upper,this.scrollState.offset))/this.values.length*r.box.height(t)),o<0&&(o=r.box.top(t)),e.container({region:r.box.construct({x:r.box.right(t)-6,y:o},{width:6,height:s}),bordered:!1,backgroundColor:i=>i.colors.gray.l6})}renderElements(e,t){const s=this.state.region;let o=0;for(const i of t){const a=this.values.dataType.equals(r.DataType.JSON)?JSON.stringify(i):i.toString();e.text({text:a,level:this.state.font,shade:11,position:r.xy.translate(r.box.topLeft(s),{x:6,y:o*this.lineHeight+6}),code:!0}),o++}}}const Uh={[lt.TYPE]:lt},Bh="roles",Fh={channel:x.access.role.SET_CHANNEL_NAME,schema:x.access.role.roleZ,onChange:({store:n,changed:e})=>{n.roles.set(e.key,e)}},$h={channel:x.access.role.DELETE_CHANNEL_NAME,schema:x.access.role.keyZ,onChange:({store:n,changed:e})=>n.roles.delete(e)},Hh={listeners:[Fh,$h]},qh="ranges",jh={channel:x.ranger.SET_CHANNEL_NAME,schema:x.ranger.payloadZ,onChange:async({store:n,changed:e,client:t})=>{const s=t.ranges.sugarOne(e),o=n.ranges.get(e.key);let i;o?.labels==null&&(i=await s.retrieveLabels());let a=null;o?.parent==null&&(a=await s.retrieveParent()),n.ranges.set(e.key,l=>t.ranges.sugarOne({...s.payload,labels:l?.labels??i,parent:l?.parent??a}))}},Wh={channel:x.ranger.DELETE_CHANNEL_NAME,schema:x.ranger.keyZ,onChange:({store:n,changed:e})=>n.ranges.delete(e)},Vh={equal:(n,e)=>r.deep.equal(n.payload,e.payload),listeners:[jh,Wh]},Ci=h.z.object({authority:r.control.authorityZ.optional(),valid:h.z.boolean().optional()}).default({authority:void 0,valid:!1}),Ri=h.z.object({triggered:h.z.boolean(),status:r.status.statusZ(Ci),sink:un.default(cn),source:Ls.default(Cs)});class es extends w.Leaf{static TYPE="Chip";schema=Ri;afterUpdate(e){const{internal:t}=this,{sink:s,source:o}=this.state;t.source=U(e,o,t.source),t.sink=qe(e,s,t.sink),this.state.triggered&&!this.prevState.triggered&&t.sink.set(this.state.status.details?.authority!==r.control.ABSOLUTE_AUTHORITY),this.updateEnabledState(),t.stopListening?.(),t.stopListening=t.source.onChange(()=>this.updateEnabledState())}updateEnabledState(){const e=this.internal.source.value();r.deep.equal(e,this.state.status)||this.setState(t=>({...t,status:e,triggered:!1}))}afterDelete(){this.internal.stopListening(),this.internal.source.cleanup?.(),this.internal.sink.cleanup?.()}render(){}}const Pi=h.z.object({}),Nr="control-state-provider",Li=x.control.stateZ.extend({subjectColor:r.color.colorZ});class ct extends w.Composite{static TYPE="StateProvider";schema=Pi;colors=new Map;colorOverrides=new Map;tracker;disconnectTrackerChange;obs=new r.observe.Observer;static use(e){return e.get(Nr)}afterUpdate(e){const{internal:t}=this;t.instrumentation=I.useInstrumentation(e,"control-state");const s=w.use(e);t.palette=s.colors.visualization.palettes.default,t.defaultColor=s.colors.gray.l8;const o=He(e);if(t.client!=null&&o===t.client)return;t.client=o,e.set(Nr,this),w.useErrorHandler(e)(async()=>{await this.maybeCloseTracker(),t.client!=null&&(this.internal.instrumentation.L.debug("starting state tracker"),await this.openTracker(t.client))},"failed to open control state tracker")}async maybeCloseTracker(){this.tracker!=null&&(this.internal.instrumentation.L.debug("stopping state tracker"),this.disconnectTrackerChange?.(),await this.tracker.close(),this.tracker=void 0)}afterDelete(e){w.useErrorHandler(e)(async()=>{await this.maybeCloseTracker()},"failed to close control state tracker")}onChange(e){return this.obs.onChange(e)}setColorOverrides(e){const t=Object.entries(e);if(!(t.length===this.colorOverrides.size&&t.every(([s,o])=>{const i=this.colorOverrides.get(s);return i!=null&&r.color.equals(i,o)}))){this.colorOverrides.clear();for(const[s,o]of t)this.colorOverrides.set(s,r.color.construct(o));this.obs.notify([])}}get(e){return Array.isArray(e)?r.unique.unique(e).map(t=>this.getOne(t)).filter(t=>t!=null):this.getOne(e)}getOne(e){if(this.tracker==null)return;const t=this.tracker.states.get(e);if(t!=null)return{...t,subjectColor:this.colorOverrides.get(t.subject.key)??this.colors.get(t.subject.key)??this.internal.defaultColor}}async openTracker(e){const{internal:t}=this,{instrumentation:s}=t;try{this.tracker=await e.control.openStateTracker()}catch{s.L.error("failed to open state tracker");return}this.disconnectTrackerChange?.(),this.disconnectTrackerChange=this.tracker.onChange(o=>{if(s.L.debug("transfer",{transfers:o.map(i=>x.control.transferString(i))}),this.tracker==null)throw new x.UnexpectedError("tracker is null inside it's own onChange callback!");this.updateColors(this.tracker),this.obs.notify(o)})}updateColors(e){const t=e.subjects(),s=t.map(a=>a.key),o=Array.from(this.colors.values());this.colors.forEach((a,l)=>!s.includes(l)&&this.colors.delete(l));const{palette:i}=this.internal;t.forEach(a=>{if(this.colors.has(a.key))return;const l=i.find(u=>!o.includes(u))??i[0];this.colors.set(a.key,l),o.push(l)})}}const ki=h.z.enum(["acquired","released","overridden","failed"]),_i=h.z.object({name:h.z.string(),authority:h.z.number().default(0),status:ki.optional(),needsControlOf:x.channel.keyZ.array().default([])}),ts={acquire:h.z.function({input:h.z.tuple([]),output:h.z.void()}),release:h.z.function({input:h.z.tuple([]),output:h.z.void()})};class ns extends w.Composite{static TYPE="Controller";static METHODS=ts;schema=_i;methods=ts;registry=new Map;writer;afterUpdate(e){const{internal:t}=this;t.instrumentation=I.useInstrumentation(e),t.addStatus=w.useAdder(e),t.runAsync=w.useErrorHandler(e);const s=He(e),o=ct.use(e);t.stateProv=o,t.telemCtx=Yo(e,this,t.telemCtx),t.client=s}afterDelete(){const{internal:e}=this;e.runAsync(()=>this.doRelease(),"failed to release control")}async updateNeedsControlOf(){const{client:e}=this.internal;if(e==null)return;const t=new Set([]);for(const o of this.registry.keys())(await o.needsControlOf(e)).forEach(a=>a!==0&&t.add(a));const s=Array.from(t);r.compare.unorderedPrimitiveArrays(this.state.needsControlOf,s)!==r.compare.EQUAL&&this.setState(o=>({...o,needsControlOf:s}))}acquire(){this.internal.runAsync(()=>this.doAcquire(),"failed to acquire control")}release(){this.internal.runAsync(()=>this.doRelease(),"failed to release control")}async doAcquire(){const{client:e,addStatus:t}=this.internal;if(e==null)return t({message:`Cannot acquire control on ${this.state.name} because no Core has been connected.`,variant:"warning"});try{await this.updateNeedsControlOf();const s=this.state.needsControlOf;if(s.length===0)return t({message:`Cannot acquire control on ${this.state.name} because there are no channels to control.`,variant:"warning"});const o=x.TimeStamp.now().sub(r.TimeSpan.milliseconds(1));this.writer=await e.openWriter({start:o,channels:s,controlSubject:{key:this.key,name:this.state.name},authorities:this.state.authority}),this.setState(i=>({...i,status:"acquired"}))}catch(s){if(this.setState(o=>({...o,status:"failed"})),!(s instanceof Error))throw s;t({variant:"error",message:`${this.state.name} failed to acquire control`,description:s.message})}}async doRelease(){try{await this.writer?.close()}catch(e){this.internal.addStatus({message:`${this.state.name} failed to release control: ${e.message}`,variant:"error"})}finally{this.setState(e=>({...e,status:"released"})),this.writer=void 0}}async set(e){this.writer==null&&await this.doAcquire(),await this.writer?.write(e)}async setAuthority(e,t){this.writer==null&&await this.doAcquire(),await this.writer?.setAuthority(Object.fromEntries(e.map(s=>[s,t])))}async releaseAuthority(e){this.writer==null&&await this.doAcquire(),await this.writer?.setAuthority(Object.fromEntries(e.map(t=>[t,this.state.authority])))}deleteTelem(e){this.registry.delete(e),this.updateNeedsControlOf()}create(e){const{internal:t}=this,o=(()=>{switch(e.type){case tn.TYPE:{const i=new tn(this,t.runAsync,e.props);return this.registry.set(i,null),i}case sn.TYPE:{const i=new sn(this,this.internal.stateProv,e.props);return this.registry.set(i,null),i}case nn.TYPE:return new nn(this,t.runAsync,e.props);default:return null}})();return o!=null&&this.updateNeedsControlOf(),o}}const Oi=h.z.object({channel:h.z.number()});class tn extends pn{static TYPE="controlled-numeric-telem-sink";controller;runAsync;schema=Oi;constructor(e,t,s){super(s),this.controller=e,this.runAsync=t}invalidate(){}cleanup(){this.controller.deleteTelem(this)}async needsControlOf(e){if(this.props.channel===0)return[];const t=await e.channels.retrieve(this.props.channel),s=[t.key];return t.index!==0&&s.push(t.index),s}set(...e){this.runAsync(async()=>{const{client:t}=this.controller.internal;if(t==null)throw new x.DisconnectedError("No Core connected");if(this.props.channel===0)throw new x.ValidationError("No command channel specified for actuator");const s=await t.channels.retrieve(this.props.channel),o={[s.key]:e};if(s.index!==0){const i=await t.channels.retrieve(s.index),a=x.TimeStamp.now();o[i.key]=Array.from({length:e.length},(l,u)=>a.add(r.TimeSpan.nanoseconds(u)))}await this.controller.set(o)},"Failed to command channel")}}const Xh=n=>({type:tn.TYPE,props:n,variant:"sink",valueType:"number"}),Mi=h.z.object({authority:h.z.number().default(x.control.ABSOLUTE_AUTHORITY),channel:h.z.number()});class nn extends pn{static TYPE="acquire-channel-control";controller;runAsync;schema=Mi;constructor(e,t,s){super(s),this.controller=e,this.runAsync=t}cleanup(){this.controller.deleteTelem(this)}async needsControlOf(e){const t=await e.channels.retrieve(this.props.channel),s=[t.key];return t.index!==0&&s.push(t.index),s}set(e){this.runAsync(async()=>{const{controller:t}=this,{client:s}=t.internal;if(s==null)return;const o=await s.channels.retrieve(this.props.channel),i=[o.key];o.index!==0&&i.push(o.index),e?await this.controller.setAuthority(i,this.props.authority):await this.controller.releaseAuthority(i)},"failed to set channel authority")}}const Gh=n=>({type:nn.TYPE,props:n,variant:"sink",valueType:"boolean"}),Di=h.z.object({channel:h.z.number()}),Kh=h.z.object({valid:h.z.boolean(),color:r.color.colorZ.optional(),authority:h.z.number()});class sn extends W{static TYPE="controlled-status-source";prov;valid=!1;stopListening;controller;schema=Di;constructor(e,t,s){super(s),this.prov=t,this.controller=e}async needsControlOf(){return[]}maybeRevalidate(){if(this.valid)return;const{channel:e}=this.props;this.stopListening?.();const t=r.control.filterTransfersByChannelKey(e);this.stopListening=this.prov.onChange(s=>{s.length>0&&t(s).length===0||this.notify?.()}),this.valid=!0}value(){this.maybeRevalidate();const e=x.TimeStamp.now();if(this.props.channel===0)return{name:this.controller.key,key:this.controller.key,variant:"disabled",message:"No Channel",time:e,details:{valid:!1,authority:0}};const t=this.prov.get(this.props.channel);return t==null?{name:this.controller.key,key:this.controller.key,variant:"disabled",message:"Uncontrolled",time:e,details:{valid:!0,color:void 0,authority:0}}:{name:this.controller.key,key:t.subject.key,variant:t.subject.key===this.controller.key?"success":"error",message:`Controlled by ${t.subject.name}`,time:e,details:{valid:!0,color:t.subjectColor,authority:t.authority}}}cleanup(){this.controller.deleteTelem(this),this.stopListening?.()}}const Qh=n=>({type:sn.TYPE,props:n,variant:"source",valueType:"status"}),Ai=h.z.object({color:r.color.colorZ.optional()}).default({color:void 0}),Ii=h.z.object({statusSource:Ls.default(Cs),colorSource:hn.default(dt),status:r.status.statusZ(Ai),color:r.color.colorZ.optional()});class ss extends w.Leaf{static TYPE="Indicator";schema=Ii;stopListeningStatus;stopListeningColor;afterUpdate(e){const{internal:t}=this,{statusSource:s,colorSource:o}=this.state;t.statusSource=U(e,s,t.statusSource),t.colorSource=U(e,o,t.colorSource),this.updateState(),this.stopListeningStatus?.(),this.stopListeningColor?.(),this.stopListeningStatus=t.statusSource.onChange(this.updateState.bind(this)),this.stopListeningColor=t.colorSource.onChange(this.updateState.bind(this))}afterDelete(){this.internal.statusSource.cleanup?.(),this.internal.colorSource.cleanup?.()}render(){}updateState(){const e=this.internal.colorSource.value(),t=this.internal.statusSource.value();r.color.equals(e,this.state.color)&&t.message===this.state.status.message&&r.color.equals(t.details?.color,this.state.status.details?.color)||this.setState(s=>({...s,color:e,status:t}))}}const zi=h.z.object({needsControlOf:x.channel.keyZ.array(),states:Li.array(),colors:h.z.record(h.z.string(),h.z.string()).default({})});class rs extends w.Leaf{static TYPE="Legend";schema=zi;afterUpdate(e){const{internal:t}=this;t.stateProv=ct.use(e),t.stateProv.setColorOverrides(this.state.colors);const s=this.state.needsControlOf;t.disconnectStateProv?.();const o=r.control.filterTransfersByChannelKey(...s),i=t.stateProv.get(s);this.setState(a=>({...a,states:i})),t.disconnectStateProv=t.stateProv.onChange(a=>{if(a.length>0&&o(a).length===0)return;const l=t.stateProv.get(s);this.setState(u=>({...u,states:l}))})}afterDelete(){const{internal:e}=this;e.disconnectStateProv?.()}render(){}}const Jh={[ns.TYPE]:ns,[ct.TYPE]:ct,[ss.TYPE]:ss,[es.TYPE]:es,[rs.TYPE]:rs},Yi=["fire","momentary","pulse"],ed=h.z.enum(Yi),Ni=h.z.object({sink:un.default(cn),mode:ed.default("fire")}),os={onMouseDown:h.z.function({input:h.z.tuple([]),output:h.z.void()}),onMouseUp:h.z.function({input:h.z.tuple([]),output:h.z.void()})};class is extends w.Leaf{static TYPE="Button";static METHODS=os;schema=Ni;methods=os;afterUpdate(e){const{sink:t}=this.state;this.internal.sink=qe(e,t,this.internal.sink)}onMouseDown(){const{mode:e}=this.state;e==="momentary"?this.internal.sink.set(!0):e==="pulse"&&this.internal.sink.set(!0,!1)}onMouseUp(){const{mode:e}=this.state;e==="fire"?this.internal.sink.set(!0):e==="momentary"&&this.internal.sink.set(!1)}afterDelete(){this.internal.sink.cleanup?.()}}const td={[is.TYPE]:is},nd=h.z.object({region:r.box.box,clearOverScan:r.xy.crudeZ.default(0),visible:h.z.boolean().default(!0),autoRenderInterval:h.z.number().default(1e3)}),Zr=["upper2d","lower2d"];class Fe extends w.Composite{static TYPE="Table";static stateZ=nd;schema=Fe.stateZ;afterUpdate(e){const{internal:t}=this;t.renderCtx=I.Context.use(e),t.handleError=w.useErrorHandler(e),t.autoRenderInterval??=setInterval(()=>this.state.visible&&this.requestRender("low"),this.state.autoRenderInterval),on(e,()=>{this.state.visible&&this.requestRender("low")}),!(!this.state.visible&&!this.prevState.visible)&&this.requestRender("high")}afterDelete(){this.internal.autoRenderInterval!=null&&clearInterval(this.internal.autoRenderInterval),this.requestRender("high")}render(){if(this.deleted)return;const e=r.box.copy(this.state.region);if(!this.state.visible)return()=>this.internal.renderCtx.erase(e,this.state.clearOverScan);const{renderCtx:t,handleError:s}=this.internal,o=r.scale.XY.translate(r.box.topLeft(this.state.region)),i=t.scissor(this.state.region,r.xy.construct(this.state.clearOverScan),Zr);try{for(const a of this.children)a.render({viewportScale:o})}catch(a){s(a,"Failed to render table")}finally{i()}return()=>this.internal.renderCtx.erase(e,this.state.clearOverScan)}requestRender(e){const{renderCtx:t}=this.internal;t.loop.set({key:`${Fe.TYPE}-${this.key}`,render:this.render.bind(this),priority:e,canvases:Zr})}}const sd={[Fe.TYPE]:Fe};h.z.enum(["small","medium","large","huge"]);const rd=h.z.object({box:r.box.box,telem:dn.default(Es),backgroundTelem:hn.default(dt),level:ge.levelZ.default("p"),color:r.color.colorZ.default(r.color.ZERO),precision:h.z.number().default(2),minWidth:h.z.number().default(60),width:h.z.number().optional(),notation:r.notation.notationZ.default("standard"),location:r.location.xy.default({x:"left",y:"center"}),units:h.z.string().default("RPM"),bounds:r.bounds.bounds.default(r.bounds.construct(0,100)),barWidth:h.z.number().default(12)}),od=["upper2d","lower2d"];class ut extends w.Leaf{static TYPE="gauge";static z=rd;schema=ut.z;afterUpdate(e){const{internal:t}=this;t.render=I.Context.use(e),t.theme=w.use(e),r.color.isZero(this.state.color)?t.textColor=t.theme.colors.gray.l8:t.textColor=this.state.color,t.telem=U(e,this.state.telem,t.telem),t.stopListening?.(),t.stopListening=t.telem.onChange(()=>this.requestRender()),t.backgroundTelem=U(e,this.state.backgroundTelem,t.backgroundTelem),t.stopListeningBackground?.(),t.stopListeningBackground=t.backgroundTelem.onChange(()=>this.requestRender()),t.requestRender=bs(e),t.strokeColor=r.color.isZero(this.state.color)?t.theme.colors.visualization.palettes.default[0]:this.state.color;const s=this.state.box,o=r.box.width(s)/2,{barWidth:i}=this.state;t.outerRadius=o-8,t.innerRadius=t.outerRadius-i;const a=Math.PI/2;t.gaugeStartAngle=3*Math.PI/4,t.gaugeAngleRange=2*Math.PI-a,t.gaugeEndAngle=t.gaugeStartAngle+t.gaugeAngleRange,t.labelRadius=t.outerRadius+12,t.labelInwardShift=12,t.centerPos=r.box.center(s);const l=t.centerPos.y+t.labelRadius*Math.sin(t.gaugeStartAngle)+6;t.minLabelPos=r.xy.construct(t.centerPos.x+t.labelRadius*Math.cos(t.gaugeStartAngle)+t.labelInwardShift,l),t.maxLabelPos=r.xy.construct(t.centerPos.x+t.labelRadius*Math.cos(t.gaugeEndAngle)-t.labelInwardShift,l),t.valueTextPos=r.xy.translateY(t.centerPos,-6),t.unitsTextPos=r.xy.translateY(t.centerPos,r.box.height(s)/9),t.textLevel=this.state.level,t.labelLevel=ge.downLevel(ge.downLevel(t.textLevel)),this.requestRender()}afterDelete(){const{internal:e}=this;e.stopListening?.(),e.stopListeningBackground?.(),e.telem.cleanup?.(),e.backgroundTelem.cleanup?.(),e.requestRender==null?e.render.erase(r.box.construct(this.state.box),r.xy.ZERO,...od):e.requestRender("layout")}requestRender(){const{requestRender:e}=this.internal;e!=null?e("layout"):this.render({})}render({viewportScale:e=r.scale.XY.IDENTITY}){const{internal:t}=this,s=t.render.upper2d.applyScale(e),o=new Ee(s,t.theme),i=t.telem.value(),{lower:a,upper:l}=this.state.bounds,u=Number(i),c=r.bounds.clamp(this.state.bounds,u),d=l-a,f=d===0?0:(c-a)/d,p=t.gaugeStartAngle+f*t.gaugeAngleRange;o.text({text:i,position:t.valueTextPos,shade:10,level:t.textLevel,align:"middle",justify:"center",weight:450,code:!0,useAtlas:!0}),o.text({text:this.state.units,position:t.unitsTextPos,shade:8,level:ge.downLevel(t.textLevel),align:"middle",justify:"center",code:!0,useAtlas:!0}),o.text({text:a.toString(),position:t.minLabelPos,shade:7,level:t.labelLevel,align:"middle",justify:"center",code:!0,useAtlas:!0}),o.text({text:l.toString(),position:t.maxLabelPos,shade:7,level:t.labelLevel,align:"middle",justify:"center",code:!0,useAtlas:!0}),o.circle({stroke:t.theme.colors.gray.l5,radius:{inner:t.innerRadius,outer:t.outerRadius},position:t.centerPos,angle:{lower:t.gaugeStartAngle,upper:t.gaugeEndAngle},lineCap:"round"}),o.circle({stroke:t.strokeColor,radius:{inner:t.innerRadius,outer:t.outerRadius},position:t.centerPos,angle:{lower:t.gaugeStartAngle,upper:p},lineCap:"round"})}}const id={[ut.TYPE]:ut},Zi=h.z.object({sink:oo.default(Jr)}),as={set:h.z.function({input:h.z.tuple([h.z.string()]),output:h.z.void()})};class ls extends w.Leaf{static TYPE="Input";static METHODS=as;schema=Zi;methods=as;afterUpdate(e){const{sink:t}=this.state;this.internal.sink=qe(e,t,this.internal.sink)}set(e){this.internal.sink.set(e)}afterDelete(){this.internal.sink.cleanup?.()}}const ad={[ls.TYPE]:ls},Ui=h.z.object({enabled:h.z.boolean(),source:Rs.default(vs)});class cs extends w.Leaf{static TYPE="Light";schema=Ui;afterUpdate(e){const{internal:t}=this;this.internal.source=U(e,this.state.source,t.source),this.updateEnabledState(),t.stopListening?.(),t.stopListening=t.source.onChange(()=>this.updateEnabledState())}updateEnabledState(){const e=this.internal.source.value();e!==this.state.enabled&&this.setState(t=>({...t,enabled:e}))}afterDelete(){this.internal.stopListening?.(),this.internal.source.cleanup?.()}}const ld={[cs.TYPE]:cs},Bi=h.z.object({value:h.z.number(),sink:ro.default(Qr),source:Ps.default(ws)}),us={set:h.z.function({input:h.z.tuple([h.z.number()]),output:h.z.void()})};class hs extends w.Leaf{static TYPE="Setpoint";static METHODS=us;schema=Bi;methods=us;afterUpdate(e){const{sink:t,source:s}=this.state,{internal:o}=this;o.source=U(e,s,o.source),o.sink=qe(e,t,o.sink),this.updateValue(),o.stopListening?.(),o.stopListening=o.source.onChange(()=>this.updateValue())}set(e){this.internal.sink.set(e)}updateValue(){const e=this.internal.source.value();e===this.state.value||isNaN(e)||this.setState(t=>({...t,value:e}))}afterDelete(){const{internal:e}=this;e.stopListening?.(),e.source.cleanup?.(),e.sink.cleanup?.()}}const cd={[hs.TYPE]:hs},ud=h.z.object({key:h.z.string(),value:h.z.number()}),Fi=h.z.object({key:h.z.string().nullable().default(null),options:h.z.array(ud).default([]),source:Ps.default(ws)});class ds extends w.Leaf{static TYPE="StateIndicator";schema=Fi;afterUpdate(e){const{internal:t}=this;this.internal.source=U(e,this.state.source,t.source),this.updateMatchedOption(),t.stopListening?.(),t.stopListening=t.source.onChange(()=>this.updateMatchedOption())}updateMatchedOption(){const e=this.internal.source.value();if(isNaN(e))return;const s=this.state.options.find(o=>o.value===e)?.key??null;s!==this.state.key&&this.setState(o=>({...o,key:s}))}afterDelete(){this.internal.stopListening?.(),this.internal.source.cleanup?.()}}const hd={[ds.TYPE]:ds},$i=h.z.object({enabled:h.z.boolean(),sink:un.default(cn),source:Rs.default(vs)}),fs={toggle:h.z.function({input:h.z.tuple([]),output:h.z.void()})};class ps extends w.Leaf{static TYPE="Toggle";static METHODS=fs;schema=$i;methods=fs;afterUpdate(e){this.internal.addStatus=w.useOptionalAdder(e);const{sink:t,source:s}=this.state,{internal:o}=this;o.source=U(e,s,o.source),o.sink=qe(e,t,o.sink),this.updateEnabledState(),o.stopListening?.(),o.stopListening=o.source.onChange(()=>this.updateEnabledState())}toggle(){const{enabled:e}=this.state;this.internal.sink.set(!e)}updateEnabledState(){const e=this.internal.source.value();e!==this.state.enabled&&this.setState(t=>({...t,enabled:e}))}afterDelete(){this.internal.stopListening?.(),this.internal.source.cleanup?.(),this.internal.sink.cleanup?.()}}const dd={[ps.TYPE]:ps},Mn={useAtlas:!0},fd=h.z.object({box:r.box.box,telem:dn.default(Es),backgroundTelem:hn.default(dt),level:ge.levelZ.default("p"),color:r.color.colorZ.default(r.color.ZERO),precision:h.z.number().default(2),stalenessTimeout:h.z.number().default(5),stalenessColor:r.color.colorZ.default(r.color.ZERO),minWidth:h.z.number().default(60),width:h.z.number().optional(),notation:r.notation.notationZ.default("standard"),location:r.location.xy.default({x:"left",y:"center"}),useWidthForBackground:h.z.boolean().default(!1),valueBackgroundShift:r.xy.xy.default(r.xy.ZERO),valueBackgroundOverScan:r.xy.xy.default(r.xy.ZERO)}),pd=["upper2d","lower2d"];class $e extends w.Leaf{static TYPE="value";static z=fd;schema=$e.z;afterUpdate(e){const{internal:t}=this;t.renderCtx=I.Context.use(e),t.theme=w.use(e),t.telem=U(e,this.state.telem,t.telem),t.stopListening?.(),t.stopListening=t.telem.onChange(()=>{t.lastReceived=performance.now(),this.requestRender()}),t.fontString=Je.fontString(t.theme,{level:this.state.level,code:!0}),t.backgroundTelem=U(e,this.state.backgroundTelem,t.backgroundTelem),t.stopListeningBackground?.(),t.stopListeningBackground=t.backgroundTelem.onChange(()=>this.requestRender()),t.requestRender=bs(e),this.requestRender()}afterDelete(){const{internal:e}=this;e.stopListening?.(),e.stopListeningBackground?.(),e.telem.cleanup?.(),e.backgroundTelem.cleanup?.(),e.requestRender==null?e.renderCtx.erase(r.box.construct(this.state.box),r.xy.ZERO,...pd):e.requestRender("layout")}requestRender(){const{requestRender:e}=this.internal;e!=null?e("layout"):this.render({})}get fontHeight(){const{theme:e}=this.internal;return e.typography[this.state.level].size*e.sizes.base}maybeUpdateWidth(e){const{theme:t}=this.internal,s=e+t.sizes.base+this.fontHeight;this.state.width==null||this.state.width+this.fontHeight*.5<s||this.state.minWidth>s&&this.state.width!==this.state.minWidth?this.setState(o=>({...o,width:Math.max(s,o.minWidth)})):this.state.width-this.fontHeight>s&&this.setState(o=>({...o,width:Math.max(s,o.minWidth)}))}getTextColor(){const{theme:e}=this.internal;return performance.now()-this.internal.lastReceived>this.state.stalenessTimeout*1e3?r.color.isZero(this.state.stalenessColor)?e.colors.warning.m1:this.state.stalenessColor:r.color.isZero(this.state.color)?r.color.pickByContrast(e.colors.border,e.colors.gray.l11,e.colors.gray.l0):r.color.pickByContrast(e.colors.border,e.colors.gray.l11,this.state.color)}render({viewportScale:e=r.scale.XY.IDENTITY}){const{renderCtx:t,telem:s,backgroundTelem:o,fontString:i,requestRender:a}=this.internal,{location:l,box:u}=this.state;if(r.box.areaIsZero(u))return;const c=r.box.topLeft(u),d=r.box.width(u),f=r.box.height(u),p=t.lower2d.applyScale(e);let g=s.value();p.font=i;const T=this.fontHeight,y=g[0]=="-";y&&(g=g.slice(1));const{theme:v}=this.internal,R=p.textDimensions(g,Mn),L=R.width+v.sizes.base,k=R.height;a==null&&t.erase(r.box.construct(this.prevState.box)),this.maybeUpdateWidth(L);const C={...r.xy.ZERO};l.x==="left"?C.x=6+T*.75:l.x==="center"&&(C.x=d/2-L/2),l.y==="center"&&(C.y=f/2+k/2);const Z=r.xy.translate(c,C);if(this.state.backgroundTelem.type!=dt.type){const M=o.value();if(!r.color.isZero(M)){p.fillStyle=r.color.hex(M);const V=this.state.useWidthForBackground?this.state.width??this.state.minWidth:r.box.width(u);p.fillRect(...r.xy.couple(r.xy.translate(c,this.state.valueBackgroundShift)),V+this.state.valueBackgroundOverScan.x,f+this.state.valueBackgroundOverScan.y)}}const b=this.getTextColor();p.fillStyle=r.color.hex(b),y&&p.fillText("-",...r.xy.couple(r.xy.translateX(Z,-T*.6)),void 0,Mn),p.fillText(g,...r.xy.couple(Z),void 0,Mn)}}const Hi={[$e.TYPE]:$e},md=Object.freeze(Object.defineProperty({__proto__:null,REGISTRY:Hi,Value:$e},Symbol.toStringTag,{value:"Module"}));exports.AcquireChannelControl=nn;exports.AuthoritySource=sn;exports.Base=we;exports.Bottom=ci;exports.Button=is;exports.Canvas=Ht;exports.Chip=es;exports.Client=Fr;exports.Controller=ns;exports.Diagram=Fl;exports.Diagram$1=xe;exports.FLUX_STORE_CONFIG=Hh;exports.FLUX_STORE_CONFIG$1=ha;exports.FLUX_STORE_CONFIG$2=Vh;exports.FLUX_STORE_KEY=Bh;exports.FLUX_STORE_KEY$1=la;exports.FLUX_STORE_KEY$2=qh;exports.Gauge=ut;exports.Indicator=ss;exports.Input=ls;exports.Legend=rs;exports.Light=cs;exports.Line=$t;exports.LinePlot=Jn;exports.Log=lt;exports.MODES=Yi;exports.Measure=at;exports.PROVIDER_TYPE=ys;exports.PROVIDER_TYPE$1=gn;exports.Provider=kt;exports.Provider$1=Jt;exports.REGISTRY=Yh;exports.REGISTRY$1=id;exports.REGISTRY$10=cd;exports.REGISTRY$11=yi;exports.REGISTRY$12=oh;exports.REGISTRY$13=Ti;exports.REGISTRY$14=Yl;exports.REGISTRY$15=ld;exports.REGISTRY$16=ad;exports.REGISTRY$17=Vo;exports.REGISTRY$18=Jh;exports.REGISTRY$19=Wo;exports.REGISTRY$2=sd;exports.REGISTRY$20=td;exports.REGISTRY$3=Uh;exports.REGISTRY$4=Hi;exports.REGISTRY$5=bi;exports.REGISTRY$6=dd;exports.REGISTRY$7=qo;exports.REGISTRY$8=Hr;exports.REGISTRY$9=hd;exports.RELATIONSHIPS_FLUX_STORE_KEY=ea;exports.RELATIONSHIP_FLUX_STORE_CONFIG=ra;exports.RESOURCES_FLUX_STORE_KEY=ta;exports.RESOURCE_FLUX_STORE_CONFIG=aa;exports.Right=hi;exports.Rule=ot;exports.ScopedUnaryStore=Ur;exports.SetChannelValue=tn;exports.Setpoint=hs;exports.StateIndicator=ds;exports.StateProvider=ct;exports.Table=Fe;exports.Toggle=ps;exports.Tooltip=it;exports.Top=ui;exports.Value=$e;exports.XAxis=en;exports.YAxis=Qt;exports.ZERO_CONTEXT_VALUE=ms;exports.acquireChannelControl=Gh;exports.acquireChannelControlPropsZ=Mi;exports.aether=eh;exports.authoritySource=Qh;exports.authoritySourceDetailsZ=Kh;exports.authoritySourceProps=Di;exports.axisStateZ=Qs;exports.baseAxisStateZ=xt;exports.buttonMethodsZ=os;exports.buttonStateZ=Ni;exports.cachedRetrieveForSubject=Wr;exports.canvas=Bl;exports.canvasStateZ=Bs;exports.channelData=fo;exports.chipStateZ=Ri;exports.chipStatusDetailsZ=Ci;exports.color=Oe;exports.colorGradient=ko;exports.control=on;exports.controllerMethodsZ=ts;exports.controllerStateZ=_i;exports.createRegistry=Ji;exports.createStore=Br;exports.diagramStateZ=Fs;exports.external=Cl;exports.indicatorStateZ=Ii;exports.indicatorStatusDetailsZ=Ai;exports.interpolate=ln;exports.interpolateNumber=nt;exports.interpolateRgb=zn;exports.interpolateString=Kr;exports.legendStateZ=zi;exports.linePlotMethodsZ=wi;exports.linePlotStateZ=vi;exports.logState=Ei;exports.measure=Mh;exports.measureStateZ=tr;exports.methodsZ=as;exports.methodsZ$1=us;exports.newCanvas=li;exports.newTickFactory=Kn;exports.parseAutoBounds=gi;exports.partialUpdate=ji;exports.provider=Gi;exports.providerStateZ=qr;exports.providerStateZ$1=xi;exports.providerStateZ$2=Us;exports.regions=me;exports.request=ie;exports.retrieveForSubject=da;exports.rollingAverage=Po;exports.rollingAverageProps=Ys;exports.ruleStateZ=Js;exports.scaleNumber=Oo;exports.scopeStore=Dn;exports.setChannelValue=Xh;exports.setChannelValuePropsZ=Oi;exports.setpoint=vo;exports.sinkPipeline=co;exports.sinkPipelinePropsZ=Ms;exports.sourcePipeline=lo;exports.sourcePipelinePropsZ=_s;exports.stateProviderStateZ=Pi;exports.stateZ=jo;exports.stateZ$1=Zi;exports.stateZ$2=Ui;exports.stateZ$3=Bi;exports.stateZ$4=Fi;exports.statusZ=ki;exports.streamChannelData=po;exports.streamChannelValue=mo;exports.streamChannelValuePropsZ=Ds;exports.stringSourceSpecZ=dn;exports.stringifyNumber=Ro;exports.stringifyNumberProps=zs;exports.sugaredStateZ=Li;exports.tickFactoryProps=Ks;exports.tickType=Gs;exports.toggleMethodsZ=fs;exports.toggleStateZ=$i;exports.tooltip=hh;exports.tooltipStateZ=er;exports.useOptionalRequestor=bs;exports.useRequestor=an;exports.value=md;exports.withinBounds=wo;exports.withinBoundsProps=Is;exports.withinSizeThreshold=fi;exports.xAxisStateZ=ih;exports.yAxisStateZ=th;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@synnaxlabs/pluto",
3
- "version": "0.52.5",
3
+ "version": "0.52.6",
4
4
  "type": "module",
5
5
  "dependencies": {
6
6
  "@fontsource-variable/inter": "^5.2.8",
@@ -24,8 +24,8 @@
24
24
  "@synnaxlabs/client": "^0.52.3",
25
25
  "@synnaxlabs/freighter": "0.52.3",
26
26
  "@synnaxlabs/media": "0.52.3",
27
- "@synnaxlabs/x": "^0.52.4",
28
- "@synnaxlabs/alamos": "^0.52.3"
27
+ "@synnaxlabs/alamos": "^0.52.3",
28
+ "@synnaxlabs/x": "^0.52.5"
29
29
  },
30
30
  "devDependencies": {
31
31
  "@juggle/resize-observer": "^3.4.0",
@@ -49,10 +49,10 @@
49
49
  "typescript": "^5.9.3",
50
50
  "vite": "^7.3.1",
51
51
  "vitest": "^3.2.4",
52
- "@synnaxlabs/stylelint-config": "^0.0.0",
53
52
  "@synnaxlabs/eslint-config": "^0.0.0",
54
- "@synnaxlabs/tsconfig": "^0.0.0",
55
- "@synnaxlabs/vite-plugin": "^0.0.0"
53
+ "@synnaxlabs/stylelint-config": "^0.0.0",
54
+ "@synnaxlabs/vite-plugin": "^0.0.0",
55
+ "@synnaxlabs/tsconfig": "^0.0.0"
56
56
  },
57
57
  "files": [
58
58
  "dist"
@@ -148,8 +148,6 @@
148
148
  },
149
149
  "./dist/*": "./dist/*"
150
150
  },
151
- "readme": "ERROR: No README data found!",
152
- "_id": "@synnaxlabs/pluto@0.0.1",
153
151
  "repository": {
154
152
  "type": "git",
155
153
  "url": "git+https://github.com/synnaxlabs/synnax.git",